Coder Social home page Coder Social logo

react-memo-component's Introduction

React Memo Component

React memorization with render children pattern.

Deprecation

Please refer to the successor @yao-react/react-memo

Install

npm install --save react-memo-component

Usage

import Memo from "react-memo-component";
// import { Memo } from "react-memo-component"; // or

<Memo
  deps={[dep1, dep2, ...]}
  render={([dep1, dep2, ...]) => <div>...</div>}
/>

Props

  • deps?: any

    Any deps of the component, common format is an array of items.

  • compare?: (prevDeps, nextDeps) => boolean

    Function used to compare the deps. If snapshots of deps are different, rerender will be triggered. By default, shallow-equal algorithm will be used if compare is not specified.

  • render?: (deps) => ReactElement
  • children?: (deps) => ReactElement

Advanced Usage

Use hooks inside render

You can use hooks inside the render function, which allows you to further optimize your render structure.

If your lint complains about it, you can write your render function as function Comp() {...}, which fools the lint to see it as a component, but you should know it is not, as it is only a normal function called inside the Memo component.

License

MIT

react-memo-component's People

Contributors

zhaoyao91 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.