GithubHelp home page GithubHelp logo

dekultura / recompact Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gregberge/recompact

0.0 2.0 0.0 927 KB

⚛ A set of React higher-order components utilities. Drop-in replacement for recompose.

Home Page: https://neoziro.github.io/recompact/

License: MIT License

Shell 0.13% JavaScript 99.11% HTML 0.76%

recompact's Introduction

Recompact

Build Status codecov

Recompact is a set of React higher-order components for reactive programming. It's a drop-in replacement of Recompose with several enhancements.

Installation and Usage

To install the stable version:

yarn add recompact

and to use it in your code:

import recompact from 'recompact'

Optimizing bundle size

The best way to reduce build size is to use babel-plugin-lodash. It can be used with other libraries than lodash, just like this:

.babelrc

{
  "plugins": [
    ["lodash", { "id": "recompact" }],
  ]
}

Transforms

import recompact from 'recompact'
import { pure, withProps } from 'recompact'

const enhance = recompact.compose(
  withProps({ className: 'beautiful' }),
  pure,
)

roughly to

import _compose from 'recompact/compose'
import _pure from 'recompact/pure'
import _withProps from 'recompact/withProps'

const enhance = _compose(
  _withProps({ className: 'beautiful' }),
  _pure,
)

Tree shaking

Since tree shaking isn't ready yet to reduce build size efficiently, it is not supported in recompact.

Recompact vs. Recompose

Recompact is a drop-in replacement* for Recompose with better performance.

* Except for the callback of withState's state updater.

Flattened React components tree

You may have noticed the "compact" keyword in "Recompact". It's the main differences between Recompose and Recompact. Recompact compacts all higher-order components into a single one. It results in a flatter React tree. A flatter React tree has several advantages: performance improvement, better debugging (especially in React Developer Tools) and easier testing.

Let's take two components using composition, one using recompose and one using recompact.

The two components are similar, but if you take a look at the React component tree (using React Developer Tool), you can see that the component using recompact is flat:

recompact-vs-recompose

New methods

Recompact also features higher-order components that are not included in Recompose:

And some very specific higher-order components that give you a lot of power:

To learn more about how to use connectObs and withObs inside your project, please refer to this complete guide about connectObs and withObs.

License

MIT

recompact's People

Contributors

gregberge avatar matthieuprat avatar vannayer avatar oliviertassinari avatar

Watchers

James Cloos 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.