
An Alternative to Props is Context

Context is not a replacement for Props , Redux
import { createContext} from "react";
const BooksContext = createContext();
BookContext(App)
< BooksContext.Provider />
<BooksContext.Provider value={valueToShare}>
{children}
</BooksContext.Provider>
value = 'value' props is special. This is what will be shared with rest app
{valueToShare} = Data being shared could be any (number, string, array , object)
{children} = This component can now access the value shared in context
import {useContext } from "react";
import BooksContext from "../context/books";
function App() {
const { num } = useContext(BooksContext);
return
<>{num}</>
}

import { createContext, useState, useCallback } from "react";
const BooksContext = createContext();
function Provider({ children }) {
// custom Provider
const [books, setBooks] = useState([]);
const valueToShare = {
books,
deleteBookById,
editBookById,
createBook,
fetchBooks,
};
return (
<BooksContext.Provider value={valueToShare}>
// valueToShare object we want to share
{children}
</BooksContext.Provider>
);
}
When 'books' state is updated, this component will rerender along with all its component.
Application state : Data that is used by many different components
Component State : Data that is used by very few component
=> Both of those are still the same exact "state" we're been working on
=> These terms are a way to figure out how to hest design your state
Hooks = Func that add additional features to a component.
useState, useEffect...
custom Hooks = functions we write to make reusable bits of logis
import {useContext } from "react";
import BooksContext from "../context/books";
function App() {
const { fetchBooks } = useContext(BooksContext);
// we always use those two togethre useContext(BooksContext)