Search code examples
reactjsfunctionreact-nativereact-reduxhelper

ReactJS: Parsing error: Export "NextQuestion" is not defined


I'm confused as to why my arrow functions are not exporting. I've received the error "Parsing error: Export 'NextQuestion' is not defined" and I'm not sure why. Here is my code:

import React, { Component } from "react"

NextQuestion = () => {
    var neww = true
    this.setState((state) => {
        return {continue: neww}
        }
    )
}

LostALife = () => {
    var newLives = this.state.lives - 1
    this.setState((state) => {
        return {lives: newLives}
        }
    )
}

export {NextQuestion, LostALife};

Solution

  • You should define your variables, use const NextQuestion, you can see the updated code below

    import React, { Component } from "react"
    
    const NextQuestion = () => {
        var neww = true
        this.setState((state) => {
            return {continue: neww}
            }
        )
    }
    
    const LostALife = () => {
        var newLives = this.state.lives - 1
        this.setState((state) => {
            return {lives: newLives}
            }
        )
    }
    
    export {NextQuestion, LostALife};