我写这个问题是因为我想请大家在如何在我的功能组件上使用redux方面提供一些帮助。我看过其他使用React组件的示例,但我不明白如何在功能组件中获得“存储”值。
我的想法是用我的
store.getState()
要检查状态并与UI交互,请在我的功能组件中进行,但我无法实现。
有什么帮助吗?
例如,一个功能组件:
import React from 'react';
import withStyles from 'isomorphic-style-loader/lib/withStyles';
import s from './Header.cs
我的redux存储中有以下数据:
data: [
0: {
name: "Mark Zuckerburg",
description: "Facebook CEO"
},
1: {
name: "Sheryl Sandberg",
description: "Facebook COO"
},
2: {
}
]
以下是我在reducer中的代码:
// This is how I store my data lists
我希望将数据从单个API显示到不同的组件,因为我只想点击API一次,并将数据分发给多个小组件。我知道我可以通过使用redux状态来完成这个任务,但是我不知道该如何做。需要你的帮助才能实现这一点。下面是到目前为止完成的代码。
homepage/index.js
import SlidingBanner from './banner/BannerList';
import Celebslider from './celebrityslider/CelebSlider';
class HomePage extends Component {
rend
这是我的_app.tsx的代码
import '../styles/globals.css'
import AppNav from '../components/AppNav'
import type { AppProps } from 'next/app'
import { store } from '../store'
import { Provider } from 'react-redux'
import { useSelector, useDispatch } from 'react-redux&