Application of methods to obtain data from other components in React
P粉449281068
P粉449281068 2023-09-03 18:00:40
0
1
335

I have a constant that receives a json data through fetch. The code is as follows:

const [user, setUser] = useState([]);

Asynchronous function users() { const result = wait fetch (My API `,{ })

const data = await result.json(); setUser(data);`

I want to display her data in another component, like only name or only ID.

I want to put the name in this little blue block: this is another component

More about the second component

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 (  ) } 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!