mercredi 8 juillet 2020

Alternative for useDispatch hook of react-redux for Class Component in React

react-redux library has come up with useDispatch, which being a hook can only be used in function component.

import React from 'react';
import {useDispatch} from 'react-redux';
import {action} from './actions';

const funComp = () => {
  const dispatch = useDispatch();
  const performAction = () => { dispatch(action()) }
  return <button onClick={performAction}> Dispatch Action </button>
}

This simplifies a lot of boiler-plate code for functional component, is there something similar which we can use in class component?

Aucun commentaire:

Enregistrer un commentaire