zoukankan      html  css  js  c++  java
  • [React Fundamentals] State Basics

    State is used for properties on a component that will change, versus static properties that are passed in. This lesson will introduce you to taking input within your React components.

    Unlike props, which are meant to be passed into our component as static values or methods, state is a collection of values that's meant to be managed by our component itself. 

    import React from 'react';
    
    export default class App extends React.Component {
        constructor(){
            super(); //This is going to give us our context for this within our component
            this.state = {
                txt: 'State',
                count: 1
            }
        }
        update(e){
            this.setState({
                txt: e.target.value
            })
        }
        render() {
            return (
                <div>
                    <input type="text" onChange={this.update.bind(this)} />
                    <span>Hello {this.state.txt}</span>
                </div>
            )
        }
    }
  • 相关阅读:
    Codeforces 1105C Ayoub and Lost Array
    绍兴市acm竞赛
    CodeForces#520 div2 1062B
    CodeForces#520 div2 1062A
    1067A
    测试MathJax
    BZOJ1010 玩具装箱toy
    停止
    秽翼
    爆零
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5771544.html
Copyright © 2011-2022 走看看