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
// views/Step2.jsx | |
import React from "react"; | |
export const Step2 = ({ navigation }) => { | |
const { previous } = navigation; | |
const submitForm = (e) => {}; | |
return ( | |
<> | |
<h3>Step 2</h3> |
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
// views/Step1.jsx | |
import React from "react"; | |
export const Step1 = ({ navigation }) => { | |
const { next } = navigation; | |
const submitForm = () => { | |
next(); | |
}; | |
return ( | |
<> |
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
// RegistrationFormStepper.jsx | |
import React from "react"; | |
import { useStep } from "react-hooks-helper"; | |
import { Step1 } from "./views/Step1"; | |
import { Step2 } from "./views/Step2"; | |
const steps = [{ id: "step1" }, { id: "step2" }]; | |
export const RegistrationFormStepper = () => { | |
const { step, navigation } = useStep({ initialStep: 0, steps }); |
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
// views/Step2.jsx | |
import React, { useState, useContext } from "react"; | |
import { GlobalContext } from "../context/global-context"; | |
export const Step2 = ({ navigation }) => { | |
const { previous } = navigation; | |
const [state, dispatch] = useContext(GlobalContext); | |
const [firstName, setFirstName] = useState(state.firstName || ""); | |
const [surname, setSurname] = useState(state.surname || ""); | |
const [submited, setSubmited] = useState(false); |
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
// views/Step1.jsx | |
import React, { useContext, useState } from "react"; | |
import { GlobalContext } from "../context/global-context"; | |
export const Step1 = ({ navigation }) => { | |
const { next } = navigation; | |
const [state, dispatch] = useContext(GlobalContext); | |
const [email, setEmail] = useState(state.email || ""); | |
const [password, setPassword] = useState(state.password || ""); |
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
// App.jsx | |
import React from "react"; | |
import "bootstrap/dist/css/bootstrap.min.css"; | |
import "./styles.scss"; | |
import { RegistrationFormStepper } from "./RegistrationFormStepper"; | |
import { GlobalContextProvider } from "./context/global-context"; | |
export default function App() { | |
return ( | |
<div className="App mt-4"> |
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
<GlobalContextProvider>{…components}</GlobalContextProvider> |
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
// global-context.jsx | |
export const GlobalContextProvider = (props) => { | |
const [state, dispatch] = useReducer(reducer, initialState); | |
return ( | |
<GlobalContext.Provider value={[state, dispatch]}> | |
{props.children} | |
</GlobalContext.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
// context/global-context.jsx | |
export const reducer = (state, action) => { | |
switch (action.type) { | |
case "SAVE_LOGIN_INFO": | |
return { | |
...state, | |
email: action.email, | |
password: action.password | |
}; | |
case "SAVE_PERSONAL_INFO": |
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
import React from "react"; | |
import { useStep } from "react-hooks-helper"; | |
import { Step1 } from "./views/Step1"; | |
import { Step2 } from "./views/Step2"; | |
const steps = [{ id: "step1" }, { id: "step2" }]; | |
export const RegistrationFormStepper = () => { | |
const { step, navigation } = useStep({ initialStep: 0, steps }); | |
const props = { navigation }; |
NewerOlder