Skip to content Skip to sidebar Skip to footer

Is There A Way To Update React Component Without Using Props?

I want to update a react component from another component not connected to each other via props. How can i?

Solution 1:

You'd have to use state somewhere above the level of both of the components. Then you have to have a method to change that state which then passes the data down via props.

Edit: So, you need to have some sort of state management, either by hooks context or some other state management, like redux, mobx, etc. For quick and dirty, use useContext.

Solution 2:

If you use classes you can do :

this.forceUpdate();

Post a Comment for "Is There A Way To Update React Component Without Using Props?"