This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// THIS IS CONTEXT CRATEION USING useReducer HOOK | |
import { createContext, useReducer } from "react"; | |
export const AgeContext = createContext(); | |
const ageReducer = (state, action) => { | |
switch (action.type) { | |
case "ADD_ONE": | |
return state + 1; | |
case "ADD_FIVE": |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const BookForm = () => { | |
const { addBook } = useContext(BookContext); | |
const [data, setData] = useState({ | |
title: "", | |
author:"", | |
}) | |
const handleChange = (e) => { | |
const { value, name } = e.target | |
setData((prev) => { | |
return { |