Doing a (GET) fetch request
class HelloMessage extends React.Component {
const [state, setState] = useState()
useEffect(()=> {
fetch(your_url)
.then(res => res.json())
.then(data => {
setState({your_state:data})
})
}, [])
render() {
return <div>Hello</div>
}
}
ReactDOM.render(
<HelloMessage />,
document.getElementById('hello-example'),
)
- Next: A simple React function component
- Previous: A Simple React Component