【发布时间】:2019-07-23 12:05:05
【问题描述】:
我创建了一个 Select 用于在页面中导航。选择选项是 NavLinks。看起来是这样的:
<Select
placeholder={PLACEHOLDER}
items={ITEMS} // array of NavLinks
{...selectState} // State of select option change
className={style.select}
/>
选项更改后我调用函数:
function useSelectState(initValue) {
const [value, setValue] = useState(initValue);
return { value, onChange: setValue }
}
所以我得到了正确的 initValue,但值永远不会改变,我无法设置值。也许有人有同样的问题?
使用选择状态:
{$$typeof: Symbol(react.element), type: ƒ, key: null, ref: null, props: {…}, …}
$$typeof: Symbol(react.element)
key: null
props: {label: "Home", path: "/"}
【问题讨论】:
-
你能展示一下选择状态是什么样子的吗?你用什么来选择
-
你的意思是对象的样子?
-
我的意思是
useSelectState返回的对象 -
添加了 useSelectState 对象
标签: reactjs typescript routing react-hooks