在nextjs中浏览页面时,如何更新redux的状态

时间:2020-07-14 10:02:41

标签: reactjs react-redux next.js server-side-rendering

所以我有一个带有项目或其他一些页面链接的侧边栏。但是,由于使用ssr,似乎我需要在每个请求上创建redux状态,因此我尝试在侧边栏组件中使用useEffect来更新redux存储状态,但是我无法实现(返回的redux状态没有更新。

现在,我需要突出显示用户当前在哪个链接上。

我正在发送要查询的网址,例如它到达服务器

localhost:3000 / faq / entry / product_id

侧边栏看起来像 enter image description here

到目前为止我尝试过的

useEffect(() => {
        var index;
        if (product_id === 'lime') index = 0
        if(product_id === 'travetine') index = 1
        console.log(entry, index)
        entryClickButton({                                  // this is the action for redux
            type: entry,
            newEntries: entry === 'new-entries' ? index : undefined,
            soldEntries: entry === 'sold-entries' ? index : undefined
        })
    }, []);

0 个答案:

没有答案