fetch("https://baconipsum.com/api/?type=meat-and-filler", )
.then((response) => {
if (response.status !== 200) {
return Promise.reject();
}
return response.json();
})
.then(res => console.log("res", res))
state.token = res
Note:
These methods are considered legacy and you should avoid them in new code:
UNSAFE_componentWillMount()
<Route path="invoices" element={<Invoices />}>
<Route path=":invoiceId" element={<Invoice />} />
</Route>
<Link
style={{ display: "block", margin: "1rem 0" }}
to={`/invoices/${invoice.number}`}
key={invoice.number}
>
{invoice.name}
</Link>
import { useParams } from "react-router-dom";
export default function Invoice() {
let params = useParams();
return <h2>Invoice: {params.invoiceId}</h2>;
}
<div id="like_button_container"></div>
Functional updates
If the new state is computed using the previous state, you can pass a function to setState. The function will receive the previous value, and return an updated value. Here’s an example of a counter component that uses both forms of setState: