how to setstate in react native code example

Example 1: set state

class App extends React.Component {

state = { count: 0 }

handleIncrement = () => {
  this.setState({ count: this.state.count + 1 })
}

handleDecrement = () => {
  this.setState({ count: this.state.count - 1 })
}
  render() {
    return (
      
{this.state.count}
) } }

Example 2: state with react functions

class Example extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      count: 0
    };
  }

  render() {
    return (
      

You clicked {this.state.count} times

); } }

Example 3: react native setstate object

this.setState({
	lang1:{
		...this.state.lang1,
		name: "myExample"
	}
})

Example 4: set state

setState({ searchTerm: event.target.value })

Example 5: reactjs update state example

{
  hasBeenClicked: false,
  currentTheme: 'blue',
}

Example 6: reactjs update state example

{
  hasBeenClicked: false,
  currentTheme: 'bluesss',
}s

Tags:

Misc Example