Application of methods to obtain data from other components in React
P粉449281068
2023-09-03 18:00:40
<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>
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.