-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor context in its own provider component
- Loading branch information
Showing
10 changed files
with
75 additions
and
78 deletions.
There are no files selected for viewing
This file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { useState, useContext, createContext, Dispatch, SetStateAction } from "react"; | ||
import { HeaderObject, EducationObject, ExperienceObject } from "./data/types"; | ||
import { | ||
initialHeaderObject, | ||
initialEducationArray, | ||
initialExperienceArray, | ||
} from "./data/initialData"; | ||
|
||
interface FormDataContext { | ||
headerObject: HeaderObject; | ||
setHeaderObject: Dispatch<SetStateAction<HeaderObject>>; | ||
educationArray: EducationObject[]; | ||
setEducationArray: Dispatch<SetStateAction<EducationObject[]>>; | ||
experienceArray: ExperienceObject[]; | ||
setExperienceArray: Dispatch<SetStateAction<ExperienceObject[]>>; | ||
} | ||
|
||
export const FormDataContext = createContext<FormDataContext | undefined>(undefined); | ||
|
||
// eslint-disable-next-line react-refresh/only-export-components | ||
export const useFormDataContext = () => { | ||
return useContext(FormDataContext); | ||
}; | ||
|
||
export const FormDataContextProvider = ({ children }) => { | ||
const [headerObject, setHeaderObject] = useState(initialHeaderObject); | ||
const [educationArray, setEducationArray] = useState(initialEducationArray); | ||
const [experienceArray, setExperienceArray] = useState(initialExperienceArray); | ||
|
||
return ( | ||
<FormDataContext.Provider | ||
value={{ | ||
headerObject, | ||
setHeaderObject, | ||
educationArray, | ||
setEducationArray, | ||
experienceArray, | ||
setExperienceArray, | ||
}}> | ||
{children} | ||
</FormDataContext.Provider> | ||
); | ||
}; |
This file contains 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 file contains 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 file contains 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 file contains 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 file contains 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 file contains 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 file contains 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 file contains 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