简体   繁体   中英

How to Change state of one component to another component in reactjs?

I am new to react, and i need to send the image to Navbar component. For example, I have Component called A, and imagine NavBar as Component B, but i have not used NavBar component directly into my Component A, instead i am calling it from index.js

It depends mostly on the way how do you get this image. If you're getting this image from API and this image needs to use in both children of App, just get this image in App.js and then pass as a prop to children.

If it's a static asset, the best choice is to import image in both components. How to do it with CRA:https://create-react-app.dev/docs/adding-images-fonts-and-files

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM