using redux with functional components code example

Example 1: using redux with hooks

import React from "react";
import { useDispatch, useSelector } from "react-redux";
import { addCount } from "./store/counter/actions";

export const Count = () => {
  const count = useSelector(state => state.counter.count);
  const dispatch = useDispatch();

  return (
    <main>
      <div>Count: {count}</div>
      <button onClick={() => dispatch(addCount())}>Add to count</button>
    </main>
  );
};

Example 2: implementation of redux in functional component

import React from 'react'
import { useSelector } from 'react-redux'

export const CounterComponent = () => {
  const counter = useSelector(state => state.counter)
  return <div>{counter}</div>
}
Copy

Example 3: useSelector

const result: any = useSelector(selector: Function, equalityFn?: Function)
Copy

Example 4: useSelector

const result: any = useSelector(selector: Function, equalityFn?: Function)
Copied