
App Component
books : [{id : 1}]
=> User Refresh Page
=>
books: []
Thsy will lose their value

The list of books is no longer going to be reset and totally releted.

VSCode
view => Extentions => rest client
Make File

# Create
GET http://localhost:3001/books HTTP/1.1
Content-Type : application/json
"scripts": {
"start": "react-scripts start",
"server": "json-server -p 3001 --watch db.json",

json-server -p 3001 --watch db.json
-p 3001 => the port the server listens to
--watch db.json => Tell the server to store data in the 'db.json'

=> npm i axios
Inside App.js
const createBook = async (title) => {
const response = await axios.post("http://localhost:3001/books", {
title,
});
const updatedBooks = [...books, response.data];
setBooks(updatedBooks);
};
const fetchBooks = async () => {
const response = await axios.get("http://localhost:3001/books");
setBooks(response.data);
};
useEffect(() => {
fetchBooks();
}, []);