ContextAPI React.js
-
Front-End
To use the useContext you need to set 3 points,
the Context setup,
the provider file and
the receiver file.
UserContext.js
import { createContext } from "react";
export const MyContext = createContext(null);
App.js
import { MyContext } from "./UserContext.js"
App()...
const [value, setValue] = useState("string");
return...
<MyContext.Provider value={{ value, setValue }}>
...
</MyContext.Provider>
MovieCard.js
import { MyContext } from "./UserContext.js"
MovieCard...
const { value, setValue } = useContext(MyContext);