// MyContext.js
import React, { createContext, useState, useContext } from 'react';
const MyContext = createContext();
export const MyProvider = ({ children }) => {
const [myState, setMyState] = useState('Initial Value');
const updateState = (newState) => {
setMyState(newState);
};
return (
<MyContext.Provider value={{ myState, updateState }}>
{children}
</MyContext.Provider>
);
};
export const useMyContext = () => {
return useContext(MyContext);
};
Comments
Post a Comment