inst.setState.bind is not a function, problems with State in react

1

I am simply trying to change a state by means of handlers in react but when executing the functions the state does not change.

Here I have the functions, the state and the objects where I send the props

It should be noted that I use webpack with babel loader

    export default class Game extends React.Component{
    constructor(){
        super()
        this.state={
            pause: null
        }

    }
    PauseShow(){
        this.setState={ pause: "block" }
        console.log("pauseshow")
    }
    PauseHide(){
        this.setState={ pause: "none" }
        console.log("pausehide")
    }
    render(){

        return(
            <div className="big-box">
                <Player idc="Game" src="assets/Fly_Me_to_the_Aegis_Seven_Moon.mp3"/>
                <GameOutput/>
                <GameData pauseMethod={this.PauseShow.bind(this)}/>
                <GameInput />
                <GamePause display={this.state.pause} pauseMethod={this.PauseHide.bind(this)}/>

            </div>
        )
    }
}

Here I call the handler I went through props

    export default class GameData extends React.Component{
    constructor(){
        super()
    }
    render(){
        return(
            <div id="GameData">
                <button onClick={this.props.pauseMethod}>pause</button>
            </div>

        )
    }
}

Here is the complete error, it happens when you press the button and operate the handler

  

backend.js: 8730 Uncaught TypeError: inst.setState.bind is not a function       at getData (chrome-extension: //fmkadmapgofadopljbjfkapdkoienihi/build/backend.js: 8730: 49)       at walkNode (chrome-extension: //fmkadmapgofadopljbjfkapdkoienihi/build/backend.js: 8576: 57)       at chrome-extension: //fmkadmapgofadopljbjfkapdkoienihi/build/backend.js: 8579: 15       at Array.forEach (native)       at walkNode (chrome-extension: //fmkadmapgofadopljbjfkapdkoienihi/build/backend.js: 8578: 20)       at chrome-extension: //fmkadmapgofadopljbjfkapdkoienihi/build/backend.js: 8579: 15       at Array.forEach (native)       at walkNode (chrome-extension: //fmkadmapgofadopljbjfkapdkoienihi/build/backend.js: 8578: 20)       at chrome-extension: //fmkadmapgofadopljbjfkapdkoienihi/build/backend.js: 8579: 15       at Array.forEach (native)

    
asked by Eivar Morales 08.06.2017 в 06:33
source

2 answers

1

You are changing the status the wrong way.

your code is this:

this.setState={ pause: "block" }

Change it to this:

this.setState=({ pause: "block" })
    
answered by 02.08.2017 в 02:31
0

The problem you have is the following:

your code: this.setState={ pause: "block" }

correct code: this.setState({ pause: "block" })

    
answered by 08.12.2017 в 22:09