useSelector useDispatcher React Example

useSelector useDispatcher - React Example

We can use useSelector and useDispatcher instead of using connect().

import React, { useEffect } from 'react';
import { useSelectoruseDispatch } from "react-redux";
import './App.css';

import {dataActionfrom './actions/getDataAction';

function App() {
  
  const data = useSelector(state => state.dataReducer);
  const dispatch = useDispatch();

  useEffect(() => {
    dispatch(dataAction())
  });

  return (
    <div className="App">
      <header className="App-header">
        <h1>{data}</h1>
      </header>
    </div>
  );
}

export default App;

Please find github project - https://github.com/codingtechlife/useSelector_useDispatcher_example


1 comment: