反应材料-UI形式组件

发布于 2025-02-11 12:54:51 字数 194 浏览 0 评论 0原文

我有一个问题,我无法从formcontent组件中获取数据值。你能帮我吗您会找到codesandbox链接

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情稳全场 2025-02-18 12:54:51

您需要将应用程序(root component)与appContext提供商包装。

  1. AppContextformcontent移动到app组件,并使用您想要的值和设置和其他功能创建上下文。
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. 现在,在两个formulairairevalidation摘要组件中使用此上下文。
export default function formulaireValidation({ submitForm }) {
   ...
   ...
  const { values, setValues } = useContext(AppContext);
  ...
  ...

}

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

工作demo

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文