@felangel/react-bloc
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

Bloc

build codecov npm version Star on Github License: MIT Discord Bloc Library


Bloc for React

This package is built to work with bloc.

Bloc Components

BlocBuilder is a React component which requires a Bloc and a builder function. BlocBuilder handles building the component in response to new states. The builder function will potentially be called many times and should be a pure function that returns a component in response to the state.

<BlocBuilder
  bloc={bloc}
  builder={count => {
    return <p>{count}</p>
  }}
/>

If you want fine-grained control over when the builder function is called you can provide an optional condition to BlocBuilder. The condition takes the previous bloc state and current bloc state and returns a boolean. If condition returns true, builder will be called with currentState and the widget will rebuild. If condition returns false, builder will not be called with currentState and no rebuild will occur.

<BlocBuilder
  bloc={bloc}
  condition={(previousState, currentState) => {
    return (previousState + currentState) % 3 === 0
  }}
  builder={count => {
    return <p>{count}</p>
  }}
/>

Maintainers

Package Sidebar

Install

npm i @felangel/react-bloc

Weekly Downloads

2

Version

0.3.0

License

MIT

Unpacked Size

1.38 MB

Total Files

14

Last publish

Collaborators

  • felangel