【发布时间】:2020-08-13 07:39:46
【问题描述】:
我是 react 新手,我想在课堂上使用 useContext,我该如何解决?这是我当前代码的示例
import { Context } from '../context/ChatListContext'
const ChatList = ({ onAction }) => {
const {state, fetchChatList} = useContext(Context)
我对我的班级也有同样的期待
import { Context } from '../context/ChatListContext'
class MainScreen extends Component {
//const {state, fetchChatList} = useContext(Context) *how do i declare this?
constructor(props) {
super(props)
this.state = { loading: true, showAction: false }
setTimeout(() => {
StatusBar.setBackgroundColor(primary)
}, 100)
}
...
}
谁能赐教?
【问题讨论】:
标签: reactjs react-native react-context use-context