Use useSelector and useDispatch in Your React Redux Application

Hi react developers in this example i am going to show you how we can use useSelector and useDispacth in our redux application to fetch data in our react js application. We can use mapStateToProps alternative way of using useSelector. And for dispatching request we can also use mapDispatchToProps rather to use of useDispatch

But mapStateToProps and mapDispatchToProps is not pretty good to use. You will able to see the differences to the advantage of using useSelector and useDispatch rather using of mapStateToProps and mapDispatchToProps. 

See the example of using mapStateToProps and mapDispatchToProps. 

 

Look, for using those above both mapStateToProps and mapDispatchToProps, we are to do many things. But if you use useSelector and useDispatch, then it will reduce your code and also it looks pretty and easily readable.

See the example of using useSelector and useDispatch

 

Read also: React Form Validation Example with Formik and Yup

 

Look and compare with above code, how pretty it is. It is very simple to use also. No need to use connect with your App component also. Hope it can help you. 

 

Facebook Github
A web enthusiastic, a self-motivated full-stack software engineer from Dhaka, Bangladesh with experience in developing applications using Laravel , React and Vue js