这里只是简单列举具体用法你们能够自行搜素react
Suspensegit
处理异步配合lazy使用方法以下 import React, {lazy, Suspense} from 'react'; const OtherComponent = lazy(() => import('./OtherComponent')); function MyComponent() { return ( <Suspense fallback={<div>Loading...</div>}> <OtherComponent /> </Suspense> ); }
react-document-titlegithub
/* react-document-title 改变文档的title */ import DocumentTitle from 'react-document-title'; return ( <React.Fragment> <DocumentTitle title={this.getPageTitle(pathname, breadcrumbNameMap)}> {/* 全局响应式断点 在布局最外层添加class 方便给不一样的元素添加响应式样式 */} <ContainerQuery query={query}> {params => ( <Context.Provider value={this.getContext()}> <div className={classNames(params)}>{layout}</div> </Context.Provider> )} </ContainerQuery> </DocumentTitle> <Suspense fallback={<PageLoading />}>{this.renderSettingDrawer()}</Suspense> </React.Fragment> );
memoize-onenpm
memoize-one 这个库的每一个实例都缓存了一个结果 记忆化库 memoizeOne(resultFn, isEqual) 接收一个结果函数和一个对比函数,对比函数为空则默认使用===来进行入参的比较。
react-container-query缓存
/* react-container-query https://www.npmjs.com/package/react-container-query 响应组件 参数 query 响应式的断点位置 props.children 须要是一个返回组件的函数 <ContainerQuery query={query}> {params => ( <Context.Provider value={this.getContext()}> <div className={classNames(params)}>{layout}</div> </Context.Provider> )} </ContainerQuery> */ import { ContainerQuery } from 'react-container-query';
classnames异步
/* https://github.com/JedWatson/classnames classNames('foo', 'bar'); // => 'foo bar' classNames('foo', { bar: true }); // => 'foo bar' classNames({ 'foo-bar': true }); // => 'foo-bar' classNames({ 'foo-bar': false }); // => '' classNames({ foo: true }, { bar: true }); // => 'foo bar' classNames({ foo: true, bar: true }); // => 'foo bar' // lots of arguments of various types classNames('foo', { bar: true, duck: false }, 'baz', { quux: true }); // => 'foo bar baz quux' // other falsy values are just ignored classNames(null, false, 'bar', undefined, 0, 1, { baz: null }, ''); // => 'bar 1' */
path-to-regexpide
/* 在路径字符串中使用正则 */ import pathToRegexp from 'path-to-regexp';
react-media函数
/* 添加响应式,根据屏幕大小返回不一样组件 */ import Media from 'react-media';
未完待续布局