根据他们的文档,使用cookies-next包,访问 cookies 客户端就像getCookie('key'); - client side
我的 Next JS 应用程序中有一个简单的功能,
const handleAddToCart = () => {
const token = getCookie('cookie-token')
console.log('token', token)
}
Run Code Online (Sandbox Code Playgroud)
我看到日志中没有返回任何内容。尽管我在检查我的开发工具时确实看到 cookie 确实存在。我在这里做错了什么?
我通过 React Select 有两个选择输入。我的第二个选择的 options 属性应该根据第一个反应选择中的值动态变化。做这个的最好方式是什么?
我的第一个选择:
<Select
styles={colourStyles}
className="basic-single"
classNamePrefix="select"
isClearable={isClearable}
isSearchable={isSearchable}
placeholder="Select service category"
name="color"
options={serviceCategoriesPrimary}
onChange={(value) =>
value !== null ? setSelectValue(value.value) : setSelectValue("")
}
/>
Run Code Online (Sandbox Code Playgroud)
我的第二个选择:
<Select
styles={colourStyles}
className="basic-single"
classNamePrefix="select"
isClearable={isClearable}
isSearchable={isSearchable}
isDisabled={selectValue === "" ? true : false}
placeholder="Select secondary category"
name="color"
options={handleChooseOptions}
/>
Run Code Online (Sandbox Code Playgroud)
const handleChooseOptions = () => {
if(selectValue === 'Health Care'){
return options1
}else{
return options2
}
}
Run Code Online (Sandbox Code Playgroud)