S
S
Sergey750il2022-02-11 15:01:11
React
Sergey750il, 2022-02-11 15:01:11

How to render data from another file?

Good day. I have a file with code

const data = fetch('https://jsonplaceholder.typicode.com/posts')
        .then(response =>  response.body)
        .catch(error => console.log(error));
export default data;

How to render content in another file?
I understand how I would do it through componentDidMount(), but I don't have class components.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dosya, 2022-02-11
@Dasihub

Use the useEffect() hook it's the same as componentDidMount() but for a functional component here is a link to the documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question