reactions/component
reactions/component has 1,059 GitHub stars and 37 forks. Star changes are not measured yet. Last checked 2026-11-09 11:19 UTC. Last push 2022-12-06.
Declarative version of React.Component
Measured star growth
- in 24h
- Update delayed
- in 7 days
- Update delayed
- in 15 days
- Update delayed
- in 1 month
- Update delayed
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalReactions Component
This has moved to Reach UI, but this repo is here for the sake of history I guess.
What?
Declarative version of React.Component.
Why?
Because sometimes you want a lifecycle or some state but don't want to create a new component. Also, this stuff is composable as heck.
Installation
npm install @reactions/component
# or
yarn add @reactions/component
And then import it:
// using es modules
import Component from "@reactions/component";
// common.js
const Component = require("@reactions/component");
// AMD
// I've forgotten but it should work.
Or use script tags and globals.
<script src="https://unpkg.com/@reactions/component"></script>
And then grab it off the global like so:
const Component = ReactionsComponent;
How?
Let's say you want some async data but don't want to make a whole new component just for the lifecycles to get it:
// import Component from '@reactions/component'
const Component = ReactComponentComponent;
ReactDOM.render(
<div>
<h2>Let's get some gists!</h2>
<Component
initialState={{ gists: null }}
didMount={({ setState }) => {
fetch("https://api.github.com/gists")
.then(res => res.json())
.then(gists => setState({ gists }));
}}
>
{({ state }) =>
state.gists ? (
<ul>
{state.gists.map(gist => (
<li key={gist.id}>{gist.description}</li>
))}
</ul>
) : (
<div>Loading...</div>
)
}
</Component>
</div>,
DOM_NODE
);
Or maybe you need a little bit of state but an entire component seems a bit heavy:
// import Component from '@reactions/component'
const Component = ReactComponentComponent;
ReactDOM.render(
<Component initialState={{ count: 0 }}>
{({ setState, state }) => (
<div>
<h2>Every app needs a counter!</h2>
<button
onClick={() =>
setState(state => ({ count: state.count - 1 }))
}
>
-
</button>
<span> {state.count} </span>
<button
onClick={() =>
setState(state => ({ count: state.count + 1 }))
}
>
+
</button>
</div>
)}
</Component>,
DOM_NODE
);
Props
You know all of these already:
didMount({ state, setState, props, forceUpdate })shouldUpdate({ state, props, nextProps, nextState })didUpdate({ state, setState, props, forceUpdate, prevProps, prevState })willUnmount({ state, props })children({ state, setState, props, forceUpdate })render({ state, setState, props, forceUpdate })
Legal
Released under MIT license.
Copyright © 2017-present Ryan Florence
Explore related projects
freeCodeCamp/freeCodeCamp
freeCodeCamp.org's open-source codebase and curriculum. Learn math, programming, and computer science for free.
458,946 starsdonnemartin/system-design-primer
Learn how to design large-scale systems. Prep for the system design interview. Includes Anki flashcards.
377,584 starsreact/react
The library for web and native user interfaces.
252,497 starsvuejs/vue
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
212,622 stars