how to fade state change in react code example

Example 1: make a fixed list in react native

export default function App() {
  const [enteredGoal,setEnteredGoal] = useState('');
  const [courseGoals, setCourseGoals] = useState([]);
  const goalInputHandler = (enteredText) => {
    setEnteredGoal(enteredText);
  }
  const addGoalHandler = () => {
    setCourseGoals(currentGoals => 
      [...currentGoals,enteredGoal]
    )
  }

  return (
    <View style={styles.screen}>
      <View>
        <View style={styles.otherview}>
          <TextInput 
          placeholder='A goal' 
          style={styles.textinput} 
          onChangeText={goalInputHandler} 
          value={enteredGoal}/>
          <Button title='Add' onPress={addGoalHandler}/>
        </View>
      </View>
        <ScrollView>
          {courseGoals.map((goal) => 
            <View key={goal} style={styles.listItem}>
              <Text>{goal}</Text>
            </View>)
          }
        </ScrollView>
	</View>

Example 2: change style on click react

Html
<div id="app"></div>

Css
button{
  width: 80px;
  height: 40px;
  margin: 15px;
}
.blackButton{
  background-color: black;
  color: white;
}

.whiteButton{
  background-color: white;
  color: black;
}

React
class Test extends React.Component {
  constructor(){
         super();

         this.state = {
              black: true
         }
    }

    changeColor(){
        this.setState({black: !this.state.black})
    }

    render(){
        let btn_class = this.state.black ? "blackButton" : "whiteButton";

        return (
             <div>
                 <button className={btn_class}
                         onClick={this.changeColor.bind(this)}>
                           Button
                  </button>
             </div>
        )
    }
}

ReactDOM.render(<Test />, document.querySelector("#app"))

Tags:

Html Example