-1

Hi I'm new to React and am trying to get the useSelector in a class component which isn't working. Any help would be greatly appreciated.

The useSelector looks like this:

const userLogin = useSelector(state => state.userLogin);
const {userInfo} = userLogin;

And I'm trying to pass it in this:

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 (

I've tried diffrent ways of passing in the state

Dace
  • 11
  • 2
  • 1
    Does this answer your question? [How can I use React hooks in React classic \`class\` component?](https://stackoverflow.com/questions/53371356/how-can-i-use-react-hooks-in-react-classic-class-component) – Emma Dec 09 '22 at 01:08

1 Answers1

0

useSelector must be used inside a function component. For Class components, maybe you want to use connect. Reference: https://react-redux.js.org/api/connect.

hungdoansy
  • 436
  • 4
  • 10