小编Luc*_*ini的帖子

如何在 getStaticProps Next.js 中访问当前语言?

我在下一个应用程序中使用 i18n,我需要在 getStaticProps 中访问当前页面语言,然后获取数据

export const getStaticProps = async () => {
  //need to get language here

  return {
    props: { data },
  };
};

const App = ({ data }) => {
  //my component where i can get language

  const { t, i18n } = useTranslation();

  const currentLang = i18n.language;
};
Run Code Online (Sandbox Code Playgroud)

i18next reactjs next.js

3
推荐指数
1
解决办法
5124
查看次数

带有 useState 的表单验证 React 函数组件

我正在使用组件函数和 useState 使用 React 来处理客户端验证表单。问题是,当我单击提交时,handleSubmit 会更新带有错误的“验证”状态,但当状态更改时它们不会呈现。仅当我在输入字段中输入一些值时才会呈现它们。我该如何解决这个问题?

您可以在下面找到代码:

import React, { useState } from 'react';

function RegistrationView() {
  const [inputValues, setInputValue] = useState({
    fName: '',
    lName: '',
    email: '',
    password: '',
    confirmPassword: '',
  });

  const [validation, setValidation] = useState({
    fName: '',
    lName: '',
    email: '',
    password: '',
    confirmPassword: '',
  });

  //handle submit updates
  function handleChange(event) {
    const { name, value } = event.target;
    setInputValue({ ...inputValues, [name]: value });
  }

  const handleSubmit = (e) => {
    e.preventDefault();
    let errors = validation;

    //first …
Run Code Online (Sandbox Code Playgroud)

reactjs use-state

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

reactjs ×2

i18next ×1

next.js ×1

use-state ×1