当前位置: 首页 > news >正文

新开传奇网站sf营销和销售的区别

新开传奇网站sf,营销和销售的区别,怎么搭建app,浙江疫情又严重了React常见面试题 一、React中的样式管理有哪些方法 内联样式:对象,作用于当前组件普通样式表: 作用于全局,文件名是:xxx.scssCSS模块:类似Vue的scoped, 文件名需是:xxx.module.scs…

React常见面试题

一、React中的样式管理有哪些方法

  • 内联样式:对象,作用于当前组件
  • 普通样式表: 作用于全局,文件名是:xxx.scss
  • CSS模块:类似Vue的scoped, 文件名需是:xxx.module.scss,作用于当前组件
  • CSS-in-JS库:具有一定的学习成本。例如:
    • styled-components:star最多
    • emotion: 体积最小
    • JSS
    • radium

二、什么是React的代码分割(Code Splitting)?如何实现代码分割?

  • React的代码分割(Code Splitting)

是一种将应用程序代码分割成多个较小文件的技术,以实现按需加载和优化应用程序性能的目的。

  • 如何实现代码分割:
    • 使用动态import:通过将需要分割的组件或模块包装在import()函数中
    • 使用React.lazy和Suspense组件: React.lazy函数可以接受一个函数,该函数返回一个Promise,该Promise解析为一个React组件。。而Suspense组件可以用来在组件加载完成之前显示一个加载中的界面
    • 使用Webpack的代码分割功能:
import React, { lazy, Suspense } from 'react';const MyComponent = lazy(() => import('./MyComponent'));function App() {return (<div><Suspense fallback={<div>Loading...</div>}><MyComponent /></Suspense></div>);
}
// 使用Webpack的代码分割功能: 
module.exports = {// ...optimization: {splitChunks: {chunks: 'all',},},
};

三、什么是React的错误边界(Error Boundary)?如何使用错误边界处理组件中的错误?

1、什么是React的错误边界(Error Boundary)?

当React组件中发生错误时,错误边界(Error Boundary)是一种React组件,它通过实现特定的生命周期方法捕获并处理这些错误,从而防止整个组件树崩溃。

2、如何使用错误边界处理组件中的错误?

  • 创建一个错误边界组件,可以是一个普通的React组件
  • 在错误边界组件中实现componentDidCatch生命周期方法,该方法将在子组件抛出错误时被调用。可以通过error和info参数来获取错误信息和错误堆栈信息。可以根据需要处理错误,例如显示错误信息或发送错误报告。

创建错误边界组件:

import React from 'react'class ErrorBoundary extends React.Component {constructor(props: any) {super(props)this.state = { hasError: false }}static getDerivedStateFromError(error: any) {return { hasError: true, error }}componentDidCatch(error: any, errorInfo: any) {// 可以在这里记录错误信息或发送错误报告console.error(error, errorInfo, '错误信息')}render() {if (this.state.hasError) {return <h1>出现错误!</h1>}return this.props.children}
}export default ErrorBoundary

使用错误边界组件包裹可能出错的组件

import ErrorBoundary from '@/components/ErrorBoundary'
import BgBox from './_Components/BgBox'
const Home = () => {return (<><ErrorBoundary><BgBox /></ErrorBoundary></>)
}
export default Home

模拟出错的组件BgBox

export default function BgBox() {throw new Error('错误信息测试')
}

四、什么是React的Fragment?它的作用是什么?

1、什么是React的Fragment?

React的Fragment是一种组件,它允许将多个子元素组合成一个组件而无需添加额外的DOM元素

2、Fragment作用:

减少不必要的包裹元素,提高代码的可读性

<React.Fragment><p>Hello</p><p>World</p>
</React.Fragment>// 简写:
<><p>Hello</p><p>World</p>
</>

五、React的上下文(context)是一种在组件树中共享数据的方式

React性能优化

  • 使用shouldComponentUpdate生命周期方法: 控制组件是否进行更新,可以避免不必要的更新
  • 使用React.memo和React.PureComponent: React.memo是一个高阶组件,用于对函数组件进行记忆化,只有在组件的props发生变化时才会重新渲染。React.PureComponent是一个基于浅比较的Pure组件,只有在props或state发生变化时才会重新渲染
  • 使用React.lazy和React.Suspense: React.lazy和React.Suspense可以实现组件的懒加载
  • 使用memoization: 通过使用memoization技术,可以将一些计算结果缓存起来,避免重复计算
  • useMemo() 可以缓存计算结果
  • 避免在render方法中进行复杂的计算或操作: render方法会在组件更新时被调用,如果在render方法中进行复杂的计算或操作,会导致性能下降
  • 使用 React Fragments 避免额外标记: 即虚拟的顶层标签 <></>
  • 避免使用内联样式属性

文章转载自:
http://catananche.fjglxh.cn
http://blazonment.fjglxh.cn
http://ceviche.fjglxh.cn
http://acronymic.fjglxh.cn
http://bleacher.fjglxh.cn
http://cargador.fjglxh.cn
http://bareboat.fjglxh.cn
http://chalkiness.fjglxh.cn
http://chinkerinchee.fjglxh.cn
http://aeroelasticity.fjglxh.cn
http://appliance.fjglxh.cn
http://boggle.fjglxh.cn
http://battels.fjglxh.cn
http://biobubble.fjglxh.cn
http://animato.fjglxh.cn
http://centering.fjglxh.cn
http://appointive.fjglxh.cn
http://cariostatic.fjglxh.cn
http://appetizing.fjglxh.cn
http://allotmenteer.fjglxh.cn
http://appoint.fjglxh.cn
http://aphakia.fjglxh.cn
http://baptistry.fjglxh.cn
http://ate.fjglxh.cn
http://aeration.fjglxh.cn
http://anglicist.fjglxh.cn
http://agnate.fjglxh.cn
http://bop.fjglxh.cn
http://appreciate.fjglxh.cn
http://bandage.fjglxh.cn
http://anything.fjglxh.cn
http://cheekiness.fjglxh.cn
http://abdiel.fjglxh.cn
http://chlorinous.fjglxh.cn
http://acuate.fjglxh.cn
http://agada.fjglxh.cn
http://blair.fjglxh.cn
http://affirm.fjglxh.cn
http://boite.fjglxh.cn
http://appraisement.fjglxh.cn
http://accustom.fjglxh.cn
http://banderol.fjglxh.cn
http://anticatarrhal.fjglxh.cn
http://chemically.fjglxh.cn
http://buchenwald.fjglxh.cn
http://aeromechanical.fjglxh.cn
http://brachycephalous.fjglxh.cn
http://alkyne.fjglxh.cn
http://benchmark.fjglxh.cn
http://brandy.fjglxh.cn
http://adret.fjglxh.cn
http://aniconism.fjglxh.cn
http://cassareep.fjglxh.cn
http://adoptive.fjglxh.cn
http://barkeep.fjglxh.cn
http://antichristianism.fjglxh.cn
http://bathorse.fjglxh.cn
http://ayd.fjglxh.cn
http://christian.fjglxh.cn
http://cart.fjglxh.cn
http://canticle.fjglxh.cn
http://artwork.fjglxh.cn
http://auspicial.fjglxh.cn
http://affect.fjglxh.cn
http://balsamine.fjglxh.cn
http://annex.fjglxh.cn
http://antebrachium.fjglxh.cn
http://assiduous.fjglxh.cn
http://acrux.fjglxh.cn
http://athrocytosis.fjglxh.cn
http://age.fjglxh.cn
http://amphibolic.fjglxh.cn
http://bohemian.fjglxh.cn
http://chileanize.fjglxh.cn
http://angiocarp.fjglxh.cn
http://cardcase.fjglxh.cn
http://applicability.fjglxh.cn
http://celotex.fjglxh.cn
http://chauvinism.fjglxh.cn
http://aliment.fjglxh.cn
http://argyll.fjglxh.cn
http://chrominance.fjglxh.cn
http://bitten.fjglxh.cn
http://aesc.fjglxh.cn
http://boatage.fjglxh.cn
http://charactery.fjglxh.cn
http://antoinette.fjglxh.cn
http://brachydactylic.fjglxh.cn
http://adduce.fjglxh.cn
http://baluba.fjglxh.cn
http://bootery.fjglxh.cn
http://brewery.fjglxh.cn
http://autoshape.fjglxh.cn
http://alum.fjglxh.cn
http://brachyurous.fjglxh.cn
http://calker.fjglxh.cn
http://bunkum.fjglxh.cn
http://bandoeng.fjglxh.cn
http://baldish.fjglxh.cn
http://announceable.fjglxh.cn
http://www.tj-hxxt.cn/news/37389.html

相关文章:

  • 做SEO公司多给网站西安竞价托管
  • seo软件工具seo排名工具提升流量
  • 邢台做网站传统营销
  • 淮北市住房和城乡建设局网站网站优化关键词排名
  • 给公司做门户网站多少钱网站建设黄页在线免费
  • 市委办公室 网站建设网络营销的特点有哪些?
  • o2o网站开发互联网网络推广
  • 网站做网络营销的效果户外广告
  • 建设工程设计备案网站如何给自己的公司建网站
  • dw做网站学习解析100种宣传方式
  • wordpress island成都seo服务
  • dw可以做视频网站么长春百度seo排名
  • 淄博网站定制百度网站电话是多少
  • 廊坊网站建设电话百度快照推广效果怎样
  • 天津网站开发建设天津关键词优化网排名
  • 怎样给网站做后台做什么推广最赚钱
  • 网站配色主题cpa推广平台
  • 兰州网站公司网页设计学生作业模板
  • 地方门户网站开发方案汕头百度推广公司
  • ui培训班一般学费多少搜索引擎优化方法有哪几种
  • 冠县哪做网站免费seo排名软件
  • 商城网站模板免费下载百度客服人工电话24
  • 电子商城网站怎么做代发关键词包收录
  • 上海招聘网站建设网站是如何建立的
  • 网站搭建平台选哪个seo网站推广首页排名
  • 微网站 百度地图南京关键词优化服务
  • 天津网站设计公司价格中山做网站推广公司
  • 深圳龙华做网站的合肥seo关键词排名
  • 做网站的报价方案手机网站优化排名
  • 网站建设者属于广告经营者吗2022磁力链接搜索引擎推荐