【发布时间】:2022-12-09 11:07:09
【问题描述】:
嗨,我是 React 的新手,正在尝试在无法正常工作的类组件中获取 useSelector。任何帮助将不胜感激。
useSelector 看起来像这样:
const userLogin = useSelector(state => state.userLogin);
const {userInfo} = userLogin;
我正试图通过它:
export class StatusReport extends Component{
constructor(props) {
super(props);
this.state = {
// Active Work Orders clients
AWOS: [],
clientIsLoading: true,
}
}
componentDidMount() {
axios.get(process.env.REACT_APP_API+'status_reports/',{
headers:{
"Accept":'application/json',
"Content-Type":'application/json'
},
})
.then(response=>{
this.setState({AWOS: response.data});
this.setState({clientIsLoading: false});
})
}
render() {
const {clientIsLoading} = this.state;
if (clientIsLoading){
return <div className={'loadingSpinner'} >Loading...<br/> <ClockLoader color="#0d00ff" /></div>
}
return (
我尝试过不同的方式通过状态
【问题讨论】:
标签: reactjs react-hooks react-redux