![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
react
大刘鸭
如果你觉得你写的代码有bug,那么它一定有bug。
展开
-
react中useState和useRef的异同
react中useState和useRef的异同原创 2022-10-24 16:47:27 · 1077 阅读 · 0 评论 -
2022react面试题整理
2022react面试题整理、react事件机制、如何在React中使用innerHTML、react中的Portal是什么、为何React事件要自己绑定this、类组件和函数组件之间的区别是啥、state 和 props 区别是啥、在构造函数调用 super 并将 props 作为参数传入的作用、React中refs的作用是什么?有哪些应用场景、原创 2022-05-20 14:21:25 · 16179 阅读 · 1 评论 -
react优化之React.memo
有如下父子组件 const Home = (props) => { const [name, setName] = useState('孩子我叫大刘鸭') const [num, setNum] = useState(0) const updateNum = () => { setNum(num + 1) } return <div> <div>我是父亲</div> <div onClick={updateNu原创 2022-01-19 10:47:21 · 434 阅读 · 0 评论 -
React组件通信
react组件通信有以下几种场景: 父子通信 父->子:通过props的方式,子组件使用this.props,就可以拿到父组件传递来的参数。 子->父:个人理解,是通过回调的方式,父组件通过props传递过来一个回调,子组件调用。 // 父组件 class Parent extends React.Component { constructor(props) { super(props); this.state = { num: 0 }; } childreCal原创 2021-10-12 14:22:17 · 115 阅读 · 0 评论 -
React类组件和函数组件之间有什么异同?
说明: 以下总结,不算HOOKS 先上代码 // 函数组件 function Welcome (props) { return <h1>Welcome {props.name}</h1> } // 类组件 class Welcome extends React.Component { constructor(props) { super(props) this.state = { } } componentDidUpdate() {原创 2021-10-09 11:10:02 · 3464 阅读 · 2 评论 -
使用 create-react-app 搭建 react 项目
1、全局安装create-react-app npm install -g create-react-app 2、创建项目 create-react-app projectName 此时,你的项目已经初步创建好,然而,项目没有webpack配置 查看项目 package.json ,发现一个特殊的命令eject 这个命令,就是将你的项目的一些配置文件,暴漏出来 执行过...原创 2019-09-06 17:10:47 · 185 阅读 · 0 评论 -
react-router-dom 之 withRouter 路由跳转,react 使用 js 跳转路由
当你在 react 项目中,需要使用 js 跳转路由的时候 直接使用this.props.history ,会报错 这个时候,需要用withRouter ,包裹你当前的组件 import { withRouter } from 'react-router-dom' class ComponentName extends React.Component { ... ... ......原创 2019-09-18 11:12:51 · 2302 阅读 · 0 评论 -
react 点击列表某一项,当前项 active ,其他项恢复默认; 单选效果,多选效果
开发中经常会遇到这样得场景 点击列表中得某一项,当前项激活,其他项恢复默认 ( 单选样式 ) 点击列表中得某一项,当前项激活,再次点击,当前项目恢复默认,不影响其他项( 多选样式 ) 上代码 test.js import React from 'react' import './test.scss' class Test extends React.Component { ...原创 2019-09-24 14:46:22 · 3647 阅读 · 0 评论