Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Abbassadri786 authored Dec 24, 2023
1 parent 4be6c18 commit 1c8f231
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/PokemonModalProvider.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { createContext, useContext, useState } from 'react';

export const PokemonModalContext = createContext();

export const usePokemonModal = () => {
return useContext(PokemonModalContext);
};

export const PokemonModalProvider = ({ children }) => {
const [modal, setModal] = useState({ isOpen: false, pokemon: null });

const value = {
currentPokemon: modal.pokemon,
openModal: (pokemon) => setModal({ isOpen: true, pokemon }),
isModalOpen: modal.isOpen,
closeModal: () => setModal((prev => ({ ...prev, isOpen: false }))),
};

return (
<PokemonModalContext.Provider value={ value }>
{ children }
</PokemonModalContext.Provider>
);
};

0 comments on commit 1c8f231

Please sign in to comment.