javascript - Reset Value Problem on Chakra UI's Select Component - Stack Overflow

I've a problem about Chakra UI's select ponent. It's somehow doesn't reset their va

I've a problem about Chakra UI's select ponent. It's somehow doesn't reset their value. Also, when I press the button, Select ponent doesn't render with new value

=/src/app.tsx:518-863

export const App = (): JSX.Element => {
  const [value, setValue] = React.useState("in");
  const onClick = () => {
    setValue(null);
  };

  console.log("App value", value);

  return (
    <div>
      <Select options={selectionOptions} value={value} />
      <Button onClick={onClick}> click </Button>
    </div>
  );
};

  const [value, setValue] = useState(propValue);

  useEffect(() => {
    if (handleChange) {
      handleChange(value);
    }
  }, [handleChange, value, setValue]);

    <Select
      {...rest}
      value={value}
      onChange={(event) => {
        setValue(event?.target?.value);
      }}
    >
      {options.map(({ value: currentValue, name }, index) => (
        <option key={index} value={currentValue}>
          {name}
        </option>
      ))}
    </Select>

I've a problem about Chakra UI's select ponent. It's somehow doesn't reset their value. Also, when I press the button, Select ponent doesn't render with new value

https://codesandbox.io/s/passionate-shockley-f9chz?file=/src/app.tsx:518-863

export const App = (): JSX.Element => {
  const [value, setValue] = React.useState("in");
  const onClick = () => {
    setValue(null);
  };

  console.log("App value", value);

  return (
    <div>
      <Select options={selectionOptions} value={value} />
      <Button onClick={onClick}> click </Button>
    </div>
  );
};

  const [value, setValue] = useState(propValue);

  useEffect(() => {
    if (handleChange) {
      handleChange(value);
    }
  }, [handleChange, value, setValue]);

    <Select
      {...rest}
      value={value}
      onChange={(event) => {
        setValue(event?.target?.value);
      }}
    >
      {options.map(({ value: currentValue, name }, index) => (
        <option key={index} value={currentValue}>
          {name}
        </option>
      ))}
    </Select>

Share Improve this question edited Feb 11, 2022 at 12:41 yasin asked Feb 11, 2022 at 12:35 yasinyasin 1412 silver badges9 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Bumped into the exact problem. I fixed it by resetting the value with setValue("") instead of setValue(null).

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745245551a4618395.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信