idev0085 / react-boilerplate

0 stars 0 forks source link

Use redux in Class and Function #110

Open idev0085 opened 2 years ago

idev0085 commented 2 years ago

For Class

const mapStateToProps = ({}) => ({  });

const mapDispatchToProps = (dispatch) => {
  return {
  };
};
export default connect(mapStateToProps, mapDispatchToProps)(AppName);

For Functional

useSelector()
const counter = useSelector(state => state.counter)

useDispatch()
export const CounterComponent = ({ value }) => {
  const dispatch = useDispatch()

  return (
    <div>
      <span>{value}</span>
      <button onClick={() => dispatch({ type: 'increment-counter' })}>
        Increment counter
      </button>
    </div>
  )
}