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
import React, { useReducer } from 'react'; | |
const cafeReducer = (state , action) => { | |
switch(action.type) { | |
case 'ADD_ORDER' : | |
return { ...state, orders: state.orders + 1 } ; | |
case 'REMOVE_ORDER' : | |
return { ...state, orders: state.orders - 1 } ; | |
default: | |
return state; | |
} |
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
import React, { useContext, useState, createContext } from 'react'; | |
// Create a context for the café (the "bulletin board") | |
const cafeContext = createContext( ); | |
const cafeProvider = ({ children }) => { | |
// State shared by the entire café | |
const [cafeStatus , setCafeStatus] = useState('Open'); | |
return { | |
<cafeContext.Provider value={{ cafeStatus, setCafeStatus }}> | |
{children} |