admin管理员组文章数量:1417099
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
1 Answer
Reset to default 5Bumped into the exact problem. I fixed it by resetting the value with setValue("")
instead of setValue(null)
.
本文标签: javascriptReset Value Problem on Chakra UI39s Select ComponentStack Overflow
版权声明:本文标题:javascript - Reset Value Problem on Chakra UI's Select Component - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745245551a2649540.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论