Paracells / react-redux-hooks-example

Simple demo for redux hooks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

React Redux Hooks Example

This is a simple example to demonstrate how to use React Redux Hooks in React Project. Hooks API is a new addition in React 16.8. They allow us to use state and other features in React Function Component.

Live Demo

Redux Hooks in this example

useSelector()

import { useSelector } from  'react-redux';

const  TodoList  = () => {

//Get todoList from todoReducer
const  todoList  =  useSelector(state  =>  state.todos.todoList);

}

useDispatch()

import { useDispatch } from  'react-redux';

//TodoList React Component
const  TodoList  = () => {

//Use for all the dispatch actions
const  dispatch  =  useDispatch();

//Add new todo item into List with the action
dispatch({type:'ADD_TODO',payload:newTodoObject});

}

TypeScript

You may want to see what's the different when using Redux Hooks use in TypeScript. Here is the TypeScript version of this example

License

MIT

About

Simple demo for redux hooks


Languages

Language:JavaScript 89.0%Language:HTML 9.9%Language:CSS 1.2%