随笔分类 - React
摘要:const App=props=>{ const [n, setN] = React.useState(0); //useState()返回一个数组,第一个是读,第二个是写 const addN = () => { //声明state和函数就相当于类组件的constructor生命周期 setN(n
阅读全文
摘要:import React from 'react' import ReactDOM from 'react-dom' import './style.css' class App extends React.Component { constructor(props) { super(props)
阅读全文
摘要:import React from 'react' const ContextDemo = React.lazy(() => import('./ContextDemo')) class App extends React.Component { constructor(props) { super
阅读全文
摘要:// 创建函数式组件 function Person (props) { console.log(props); let { name, age, sex } = props; // 解构赋值 return ( <ul> <li>姓名: {name}</li> <li>性别: {sex}</li>
阅读全文
摘要:import React from 'react' // 函数组件(后面会讲),默认没有 state class StateDemo extends React.Component { constructor(props) { super(props) // 第一,state 要在构造函数中定义 t
阅读全文
摘要:受控组件 import React from 'react' class FormDemo extends React.Component { constructor(props) { super(props) this.state = { name: 'ljx', info: '个人信息', ci
阅读全文
摘要:自定义组件中,render只能渲染一个标签。 要使用JSX语法,必须导入react模块。 render函数中最常用的单标签是fragment标签,因为fragment标签仅仅起到占位作用,不会改变dom结构。 react中,标签绑定事件,一定要注意大小写,如<input onChange = {th
阅读全文