React 16.8 Includes Hooks this was the first version so far in the react history when hooks were first introduced .
import React, { useState, useEffect } from 'react';
function Example() {
const [data, setData] = useState([]);
useEffect(() => {
fetch('https://jsonplaceholder.typicode.com/posts')
.then(response => response.json())
.then(json => setData(json))
.catch(error => console.error(error));
}, []);
return (
<div>
{data.map(post => (
<div key={post.id}>
<h2>{post.title}</h2>
<p>{post.body}</p>
</div>
))}
</div>
);
}
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.