React Material-ui form component

Viewed 51

I have a problem I can't get the data values ​​from the formContent component. Can you help me please. You will find the codesandbox link

summaryForm

1 Answers

You need to wrap your App (root component) with the AppContext provider.

  1. Move AppContext from formContent to App component and create context with values and setters and other functions you want.
export const AppContext = createContext({
  activeStep: 0,
  values: [],
  handleFormChange() {},
  handleNext() {},
  handleBack() {}
});

export default function App() {
  const [values, setValues] = useState({
    nni: "",
    nom: "",
    prenom: "",
    email: "",
    typeHabilitation: "",
    perimetreHabilitation: ""
  });

  return (
    <AppContext.Provider value={{ values, setValues }}>
      <Form />
    </AppContext.Provider>
  );
}
  1. Now use this context in both formulaireValidation and SummaryForm components.
export default function formulaireValidation({ submitForm }) {
   ...
   ...
  const { values, setValues } = useContext(AppContext);
  ...
  ...

}

export default function SummaryForm(props) {
  const { values, handleBack, handleNext } = useContext(AppContext);
  ...
  ...
}

Working Demo

Edit formulaire v2 (forked)

Related