【发布时间】:2020-10-22 05:53:04
【问题描述】:
我有以下路线:
const makeIndexRoutes = (): React.ReactElement => (
<Switch>
<Redirect exact from="/" to="/estimates" />
<Route exact path="/estimates" component={CostingPage} />
<Route exact path="/estimates/new" component={NewEstimatePage} />
<Route exact path="/estimates/edit/:id" component={EditEstimatePage} />
</Switch>
);
在另一个文件中,我尝试对按钮单击进行重定向,如下所示:
const handleClose = useCallback(() => {
// do some action on 'close' button click
<Redirect to='/estimates'></Redirect>
}, []);
但是什么都没有发生,有没有人能够指导我了解我可能做错了什么?
【问题讨论】:
-
这是一个 useCallback 而不是常规函数有什么具体原因吗?
-
根据最佳实践我们应该使用useCallback。
-
这取决于:)
-
你能解释更多吗?有链接吗?
-
kentcdodds.com/blog/usememo-and-usecallback 他解释什么时候不该什么时候该
标签: reactjs typescript react-router