“Setstate” Ответ

реагировать конструктор компонента нативного класса

import React from 'react';  
import { View, TextInput } from "react-native";

class App extends React.Component {  
  constructor(props){  
    super(props);  
    this.state = {  
         name: "" 
      }  
    this.handleChange = this.handleChange.bind(this);  
  }
  handleChange(text){
    this.setState({ name: text })
    console.log(this.props);  
  }  
  render() {  
    return (  
    <View>
      <TextInput 
      	value={this.state.name} 
  		onChangeText={(text) =>this.handleChange(text)}
      />
    </View>  
  }  
}  
export default App;  
Open Owl

Как определить состояние в функции React

import React, { useState } from 'react';

function Example() {
  // Declare a new state variable, which we'll call "count" 
  const [count, setCount] = useState(0);
  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}
Spotless Spider

Setstate

this.setState((state, props) => ({
  counter: state.counter + props.increment
}));
Thoughtless Tarantula

Setstate

this.setState((state, props) => ({
  counter: state.counter + props.increment
}));
Thoughtless Tarantula

Setstate

this.setState((state, props) => ({
  counter: state.counter + props.increment
}));
Thoughtless Tarantula

Setstate

this.setState((state, props) => ({
  counter: state.counter + props.increment
}));
Thoughtless Tarantula

Смотреть популярные ответы по языку

Смотреть другие языки программирования