Application of methods to obtain data from other components in React
P粉449281068
P粉449281068 2023-09-03 18:00:40
0
1
374
<p>I have a constant that receives a json data through fetch. The code is as follows: </p> <p><code>const [user, setUser] = useState([]);</code></p> <p><code> Asynchronous function users() { const result = wait fetch (</code>My API `,{ })</p> <pre class="brush:php;toolbar:false;">const data = await result.json(); setUser(data);`</pre> <p>I want to display her data in another component, like only name or only ID. </p> <p>I want to put the name in this little blue block: this is another component</p> <p>More about the second component</p>
P粉449281068
P粉449281068

reply all(1)
P粉633075725

The first component is the component that gets the data, and the second component is the component that displays the data, because you receive user data through props.

function FirstComponent(){
const [user, setUser] = useState([]);

 return (
   <SecondComponent user={user} />
 )
}

function SecondComponent({user}){
 console.log(user)

 return (
   //这里是你展示图片的代码
 )
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!