Skip to content

Instantly share code, notes, and snippets.

View mishaj-7's full-sized avatar
🎯
Focusing

mishaj_k mishaj-7

🎯
Focusing
View GitHub Profile
@mishaj-7
mishaj-7 / create context with useReducer
Created May 8, 2024 08:27
useReaducer hook using context
// 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":
@mishaj-7
mishaj-7 / react controlled cmpnt
Created May 8, 2024 06:47
controlled component
const BookForm = () => {
const { addBook } = useContext(BookContext);
const [data, setData] = useState({
title: "",
author:"",
})
const handleChange = (e) => {
const { value, name } = e.target
setData((prev) => {
return {