Element type is invalid: expected a string or a class/function (for composite components) but got: undefined react

Viewed 1032

I already searched for solutions and found many but they don't fit my problem.so I don't know how to solve this problem.

this is full error:-

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Check the render method of WithAuthentication.

and this is withAuthentication.js file

import React from 'react'

import AuthUserContext from './context'
import { withFirebase } from '../Firebase'

const withAuthentication = (Component) => {
    class WithAuthentication extends Component {
        constructor(props) {
            super(props)    
            this.state = {
                authUser: null,
            }
        }
            componentDidMount() {
            this.listener = this.props.firebase.auth.onAuthStateChanged(
                (authUser) => {
                    authUser
                        ? this.setState({ authUser })
                        : this.setState({ authUser: null })
                }
            )
        }    
        componentWillUnmount() {
            this.listener()
        }
            render() {
            return (
                <AuthUserContext.Provider value={this.state.authUser}>
                    <Component {...this.props} />
                </AuthUserContext.Provider>
            )
        }
    }    
    return withFirebase(WithAuthentication)
}    
export default withAuthentication
1 Answers

I solved it by changing extend Component to extend React.Component

Related