我需要使用 Redux.State 通过钩子制作表单,我得到这样的:
const searchValue = useSelector(state => state.Search.searchValue);
如何获取将参数传递到其中并实现它的函数?我尝试了使用调度((,但没有任何结果。有必要对此输入进行onChange,并且还需要获取另一个带有参数的函数。
<InputBase
placeholder="Search…"
value={searchValue}
classes={{
root: classes.inputRoot,
input: classes.inputInput,
}}
inputProps={{ 'aria-label': 'search' }}
/>
//import your related action function in store
import reduxStoreActionFunction from <your store path>
const YourFunctionComponent = () => {
const dispatch = useDispatch()
//if you want to do it by form, you should have a onSubmitFunction to handle what should be done after pressing submit button
const handleOnSubmit = () => dispatch(reduxStoreActionFunction(searchValue))
return (
<>
<Form onSubmit={handleOnSubmit}>
<InputBase
placeholder="Search…"
value={searchValue}
classes={{
root: classes.inputRoot,
input: classes.inputInput,
}}/>
<input type="submit"/>
</Form>
</>
/>
)
}