摘要:index.js import React, { Component } from 'react' import ReactDOM from 'react-dom' class Bar extends Component { constructor() { super() this.state =
阅读全文
摘要:index.js import React from 'react' import ReactDOM from 'react-dom' const UserNameInput = ({ getName }) => { return ( <input onInput={function (e) { g
阅读全文
摘要:index.js import React from 'react' import ReactDOM from 'react-dom' const element = <h1>hello</h1> // 这是一个 React 元素 ReactDOM.render(element, document.
阅读全文
摘要:App.jsx import React from 'react' class App extends React.Component { render() { return <h3>Hello</h3> } } export default App index.js import React fr
阅读全文
摘要:index.js import React from 'react' import ReactDOM from 'react-dom' function Name({ name }) { return <span style={{ color: 'tomato' }}>{name}</span> }
阅读全文
摘要:事件监听函数内部使用 this 会报错,原因是 this 的指向变成了事件触发对应的 DOM 节点,因此需要固定 this,方法有三种: index.js import React from 'react' import ReactDOM from 'react-dom' class Counter
阅读全文
摘要:index.js import React from 'react' import ReactDOM from 'react-dom' function render() { const element = <h1>{new Date().toLocaleTimeString()}</h1> Rea
阅读全文
摘要:index.js import React from 'react' import ReactDOM from 'react-dom' class Clock extends React.Component { constructor() { super() this.state = { time:
阅读全文
摘要:index.js import React, { Component } from 'react' import ReactDOM from 'react-dom' class App extends Component { clickHandler = name => { alert(name)
阅读全文
摘要:index.js import React from "react"; class App extends React.Component { render() { return <h1>Hello, World!</h1>; } }
阅读全文
摘要:yarn yarn create react-app my-app
阅读全文
摘要:index.js import React from 'react' import ReactDOM from 'react-dom' class ANumber extends React.Component { constructor() { super() this.state = { num
阅读全文
摘要:index.js import React from 'react' import ReactDOM from 'react-dom' class Btn extends React.Component { render() { return <button onClick={() => alert
阅读全文