【问题标题】:Invalid hook call even if everything is right即使一切正常,挂钩调用也无效
【发布时间】:2021-01-07 19:40:16
【问题描述】:

我最近每次使用钩子时都会收到此警告,我不知道该怎么办,我向您保证上述 3 个可能的原因(重复反应、不匹配的版本或损坏的钩子规则)都不成立是的,但我仍然遇到了这个问题

const WelcomeScreen = ({ match, location }) => {
    const dispatch = useDispatch();
    const state = useSelector(state => state.first)
    const id = match.params.id
    const { examDetails, loading } = state;

    useEffect(() => {
        dispatch(getInstituteDetails(id))
    }, [dispatch, id])

    if (loading)
        return <h3>Loading...</h3>
    
    console.log(examDetails);
    return {...

它显示在第二行本身

【问题讨论】:

标签: javascript reactjs react-redux react-hooks


【解决方案1】:

您在react-router-dom 中使用了错误的 API:

// not render={WelcomeScreen}
<Route component={WelcomeScreen} path="/" exact />

https://codesandbox.io/s/confident-thompson-ujlxf?file=/src/error.js

【讨论】:

    猜你喜欢
    • 2019-03-15
    • 2020-08-13
    • 2018-11-12
    • 2021-12-07
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    • 1970-01-01
    • 2021-09-08
    相关资源
    最近更新 更多