Skip to content

Instantly share code, notes, and snippets.

@SeanDunford
Last active April 28, 2022 20:06
Show Gist options
  • Save SeanDunford/47ea662a4cf7c366fc9db6262d5b3367 to your computer and use it in GitHub Desktop.
Save SeanDunford/47ea662a4cf7c366fc9db6262d5b3367 to your computer and use it in GitHub Desktop.
Prototype for a multistep form in react native using hooks
/* eslint-disable no-shadow, react/prop-types */
/* This is just temporary as this onboarding needs to be refactored */
import React, { useState } from 'react';
import { StyleSheet, Text } from 'react-native';
import { ScreenView } from '../../shared';
import { dimensions } from '../../../styles';
import { colors } from '../../../styles/colors';
import FirstName from './FirstName';
const styles = StyleSheet.create({
container: {
height: '100%',
width: '100%',
flex: 1,
backgroundColor: colors.black,
},
foreground1: {
flex: 1,
margin: dimensions.defaultSpace,
},
foreground2: {
flex: 1,
margin: dimensions.defaultSpace,
},
foreground3: {
flex: 1,
margin: dimensions.defaultSpace,
},
});
// Changing order will change step order
const steps = [FirstName];
const Registration = () => {
const [step, setStep] = useState(0);
const [user, setUser] = useState({});
const nextStep = () => {
setStep(step + 1);
};
const prevStep = () => {
setStep(step - 1);
};
const handleChange = (fieldName, value) => {
if (user[fieldName] === value) {
return;
}
setUser({ ...user, [fieldName]: value });
};
const CurrentStep = steps[step];
return (
<ScreenView>
<Text style={styles.propmpt}>Tell Us About Yourself</Text>
<CurrentStep
prevStep={prevStep}
nextStep={nextStep}
handleChange={handleChange}
{...user}
/>
</ScreenView>
);
};
export default Registration;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment