Skip to content

Instantly share code, notes, and snippets.

@robabby
Created January 3, 2018 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robabby/5f72edde102f0b888101b53614184f39 to your computer and use it in GitHub Desktop.
Save robabby/5f72edde102f0b888101b53614184f39 to your computer and use it in GitHub Desktop.
[Functional setState] #react
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