
Submitted 3 months ago
Multi Step Form | ⚛️ReactJS+🎨TailwindCSS+🌊Framer Motion
#framer-motion#react#tailwind-css#accessibility
@MahmoodHashem
Design comparison
SolutionDesign
Solution retrospective
What are you most proud of, and what would you do differently next time?
👋 Hello FM Friends!
This project provided a great opportunity to learn about context in React.
-
Context is used to define a state accessible throughout the application.
-
Main Functions:
- createContext: Used to define the context.
- Example:
FormContext = createContext()
- Example:
- useContext: Used to consume the context.
- createContext: Used to define the context.
-
Provider:
- Supplies the context.
- Implemented using:
{children}
- Purpose:
- Allows access to
currentStep
,setCurrentStep
,formData
, andupdateFormData
across the application. - Changes in one part of the application reflect in all parts using these values.
- Allows access to
-
Consumer:
- To access contextualized states, use:
const { currentStep, setCurrentStep, formData, updateFormData } = useContext(FormContext);
- Functionality: Returns an object containing all data about the corresponding contextualized states.
- To access contextualized states, use:
- FormProvider Component:
export const FormProvider = ({ children }) => { const [currentStep, setCurrentStep] = useState(1); const [formData, setFormData] = useState({ personalInfo: { name: '', email: '', phone: '' }, plan: { type: 'arcade', isYearly: false }, addons: [] }); const updateFormData = (step, data) => { setFormData(prev => ({ ...prev, [step]: data })); }; return ( {children} ); };
- Usage: Wrap your App component (or any component that requires the context) with FormProvider.
Any feedback is appreciated
Community feedback
- @khaduj03Posted 3 months ago
Wow, great project, especially the animations—they're so smooth ✨. Best wishes for you, bro! 👏🔥
Marked as helpful1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord