Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to re-render a component from another component in React

I'm new to react and here is my question , is there's a way to re-render a component from another component?

I'm using Redux and some of the global state is effecting component B . But in my example component B is not re-rendered after some Redux state is changing from component C .

component C and B are not father/child to each other , is there a simple way to do it?

thanks

like image 634
Arik Jordan Graham Avatar asked Oct 20 '25 11:10

Arik Jordan Graham


2 Answers

Every component will re-render if any of the states connected to it change. So in order to cause a re-render, simply include that state in both components connect function.

like image 90
YTG Avatar answered Oct 22 '25 04:10

YTG


There is an option on how to re-render component inside component in React 16.x using Fragments. Documentation on this can be found here.

Short explanation: Your DOM will not be polluted with extra nodes, but will allow your app to use less memory which is always great. More in-depth explanation available here.

like image 31
Malakai Avatar answered Oct 22 '25 04:10

Malakai