Created
January 3, 2018 15:23
-
-
Save robabby/5f72edde102f0b888101b53614184f39 to your computer and use it in GitHub Desktop.
[Functional setState] #react
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
// Optional import from external file | |
import { increaseScore } from "../stateChanges" | |
// outside your component class | |
function increaseScore (state, props) { | |
return { score : state.score + 1 } | |
} | |
class User extends React.Component { | |
constructor(props) { | |
super(props) | |
} | |
// inside your component class | |
handleIncreaseScore () { | |
this.setState(increaseScore) | |
} | |
render() { | |
return ( | |
<div>User Component</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment