Gathering detailed insights and metrics for @truefit/bach
Gathering detailed insights and metrics for @truefit/bach
Gathering detailed insights and metrics for @truefit/bach
Gathering detailed insights and metrics for @truefit/bach
@truefit/bach-recompose
set of enhancers for @truefit/bach inspired by recompose
@truefit/bach-redux
compose your react-redux components in style
@truefit/bach-rn-elements
compose your react native elements based components in style
@truefit/bach-formik
compose your formik based components in style
A utility library that allows React developers to compose components in a functional manner.
npm install @truefit/bach
Typescript
Module System
Node Version
NPM Version
TypeScript (95.83%)
JavaScript (4.17%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
57 Stars
106 Commits
5 Forks
9 Watchers
10 Branches
10 Contributors
Updated on May 29, 2025
Latest Version
2.5.1
Package Id
@truefit/bach@2.5.1
Unpacked Size
113.15 kB
Size
27.42 kB
File Count
89
NPM Version
9.6.5
Node Version
18.13.0
Published on
Jun 26, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
Bach is a utility library the allows React developer to compose their components in a functional manner.
The goal is to help create a codebase that is readable, flexible, testable, and maintainable. In our experience, following this convention generally leads to a collection of single use, small functions that can easily be shared across a codebase. The ideal is that components should be focused on rendering, allowing other concerns to be coded elsewhere and passed in.
You can find a full React project with simple working examples of each hook, as well as more complex examples that combine hooks here: https://github.com/TrueFit/bach-examples.
With the release of version 2.0, Bach has been updated to Typescript.
We did our best to maintain backwards compatibility and believe we have. If you find something, please let us know.
At a high level, we liked the syntax that Recompose enabled in our source. The advent of React hooks has forced us to move away from recompose since it has a couple of major drawbacks in this new world (no hooks, HOC hell, and the author deprecated it). We searched for a comparable library in the community, but were unable to find one that fit our needs.
At this point you may be asking, why not just use hooks - which is a fair question. In short, we aren't really fans of the syntax of hooks. In our opinion, they tend to add a lot of code and concerns to a component that don't belong in a presentational function. That said, we definitely embrace the push towards functional components that has come along with React's introduction of hooks - we just find the compositional approach to produce "better" code.
Thus we decided to write this library to fill the hole in the community the deprecation of recompose left. We set the following guidelines for the library:
We are pretty happy with where we ended up and hope it will prove helpful not just to us, but also the React community at large. We welcome questions, thoughts, and contributions from the community (see Contributing below). If you use it and find it helpful, we'd love to hear about that as well.
npm install @truefit/bach
or
yarn add @truefit/bach
1import React from 'react'; 2import {compose, withCallback} from '@truefit/bach'; 3 4type Props = { 5 handeClick: () => void; 6} 7 8const Component = ({handleClick}: Props) => ( 9 <div> 10 <button onClick={handleClick}> 11 Click Me 12 </button> 13 </div> 14); 15 16export default compose<Props>( 17 withCallback<Props>('handleClick', () => () => { 18 alert('Hello There'); 19 }), 20)(Component);
1import React from 'react'; 2import {compose, withCallback} from '@truefit/bach'; 3 4const Component = ({handleClick}) => ( 5 <div> 6 <button onClick={handleClick}> 7 Click Me 8 </button> 9 </div> 10); 11 12export default compose( 13 withCallback('handleClick', () => () => { 14 alert('Hello There'); 15 }), 16)(Component);
Enhancers are the central mechanism for composing components with @truefit/bach. In general, you will declare a series of enhancers for each component that together compose all of the supporting logic that component needs to render. For example, you commonly have a couple of state enhancers combined with callbacks and effects.
Underneath the covers, @truefit/bach does things a little differently than its predecessors. Rather than have a a huge tree of HOCs wrapping your component, the compose function combines all of your enhancers into a single HOC generated at runtime. This allows your code to follow all of the hook rules while still being composed functionally.
Order matters: we keep the definition of the generated code in the same order you put your enhancers in the compose call, thus code only has access to the properties defined before it.
As discussed below, this library was built with React Hooks in mind, thus the base library (this one) is restricted to having React as it's sole dependency. We wrapped all of the standard React hooks, except for useImperativeHandle (we still haven't seen a good use for it) and useDebugValue (it's targeted at custom hooks which are outside of the scope of this library).
Creates a memoized callback passed to component with the name specified.
Enhancer Signature
Parameter | Type | Description |
---|---|---|
callbackName | string | the name of the callback in the props passed to the wrapped component |
fn | function | the function to invoke when the callback is invoked by the component |
conditions | string[] | names of the properties on the props object react should restrict the revaluation of this callback to |
Example 1
1import React from 'react'; 2import {compose, withCallback} from '@truefit/bach'; 3 4type Props = { 5 handeClick: () => void; 6} 7 8const Component = ({handleClick}: Props) => ( 9 <div> 10 <button onClick={handleClick}> 11 Click Me 12 </button> 13 </div> 14); 15 16export default compose<Props>( 17 withCallback<Props>('handleClick', () => () => { 18 alert('Hello There'); 19 }), 20)(Component);
1import React from 'react'; 2import {compose, withCallback} from '@truefit/bach'; 3 4const Component = ({handleClick}) => ( 5 <div> 6 <button onClick={handleClick}> 7 Click Me 8 </button> 9 </div> 10); 11 12export default compose( 13 withCallback('handleClick', (props) => () => { 14 alert('Hello There'); 15 }), 16)(Component);
Example 2
1import React from 'react'; 2import {compose, withState, withCallback} from '@truefit/bach'; 3 4type Props = { 5 count: number; 6 setCount: (n: number) => void; 7 8 alterCount: (n: number) => () => void; 9} 10 11const Component = ({count, alterCount}) => ( 12 <div> 13 <h1>With Callback And State</h1> 14 <div> 15 <h2>Count: {count}</h2> 16 <button onClick={alterCount(1)}>Increment</button> 17 <button onClick={alterCount(-1)}>Decrement</button> 18 </div> 19 </div> 20); 21 22export default compose( 23 withState<Props, number>('count', 'setCount', 0), 24 25 withCallback<Props>('alterCount', ({count, setCount}: Props) => (delta: number) => () => { 26 setCount(count + delta); 27 }), 28)(Component);
1import React from 'react'; 2import {compose, withState, withCallback} from '@truefit/bach'; 3 4const Component = ({count, alterCount}) => ( 5 <div> 6 <h1>With Callback And State</h1> 7 <div> 8 <h2>Count: {count}</h2> 9 <button onClick={alterCount(1)}>Increment</button> 10 <button onClick={alterCount(-1)}>Decrement</button> 11 </div> 12 </div> 13); 14 15export default compose( 16 withState('count', 'setCount', 0), 17 18 withCallback('alterCount', ({count, setCount}) => delta => () => { 19 setCount(count + delta); 20 }), 21)(Component);
React Hook
Accepts a context object and returns the current context value for that context.
Enhancer Signature
Parameter | Type | Description |
---|---|---|
contextProperty | string[] | the names of the props in the context that are mapped to the props passed to the wrapped component |
contextSource | Context or string | either the context object or the name of the prop in the HOC that points to the context to use as source |
Example
1import React from 'react'; 2import {compose, withContext} from '@truefit/bach'; 3 4type Props = { 5 message: string; 6}; 7 8type Context = { 9 message: string; 10}; 11 12const context = React.createContext<Context>({message: 'Hello There'}); 13 14const Component = ({message}: Props) => { 15 return ( 16 <div> 17 <h1>With Context</h1> 18 <div> 19 <h2>{message}</h2> 20 </div> 21 </div> 22 ); 23}; 24 25export default compose( 26 withContext<Context>(['message'], context) 27)(Component);
1import React from 'react'; 2import {compose, withContext} from '@truefit/bach'; 3 4const context = React.createContext({message: 'Hello Child'}); 5 6const Component = ({message}) => { 7 return ( 8 <div> 9 <h1>With Context</h1> 10 <div> 11 <h2>{message}</h2> 12 </div> 13 </div> 14 ); 15}; 16 17export default compose( 18 withContext(['message'], context) 19)(Component);
React Hook
Accepts a function that contains imperative, possibly effect creating code.
Enhancer Signature
Parameter | Type | Description |
---|---|---|
fn | function | the function to invoke when the values of properties change on the wrapped component |
conditions | string[] | names of the properties on the props object react should restrict the firing of the function to |
Example
1import React from 'react'; 2import {compose, withEffect} from '@truefit/bach'; 3 4const Component = () => ( 5 <div> 6 <h1>With Effect</h1> 7 </div> 8); 9 10export default compose( 11 withEffect(() => { 12 console.log('Effect Fired'); 13 }), 14)(Component);
1import React from 'react'; 2import {compose, withEffect} from '@truefit/bach'; 3 4const Component = () => ( 5 <div> 6 <h1>With Effect</h1> 7 </div> 8); 9 10export default compose( 11 withEffect((props) => { 12 console.log('Effect Fired'); 13 }), 14)(Component);
React Hook
Like withEffect, but used for the times when invocation cannot be deferred, thus it fires synchronously after all DOM mutations.
Enhancer Signature
Parameter | Type | Description |
---|---|---|
fn | function | the function to invoke when the values of properties change on the wrapped component |
conditions | string[] | names of the properties on the props object react should restrict the firing of the function to |
Example
1import React from 'react'; 2import {compose, withLayoutEffect} from '@truefit/bach'; 3 4const Component = () => ( 5 <div> 6 <h1>With Effect</h1> 7 </div> 8); 9 10export default compose( 11 withLayoutEffect(() => { 12 console.log('Effect Fired'); 13 }), 14)(Component);
1import React from 'react'; 2import {compose, withLayoutEffect} from '@truefit/bach'; 3 4const Component = () => ( 5 <div> 6 <h1>With Effect</h1> 7 </div> 8); 9 10export default compose( 11 withLayoutEffect((props) => { 12 console.log('Effect Fired'); 13 }), 14)(Component);
React Hook
Creates a memoized value.
Enhancer Signature
Parameter | Type | Description |
---|---|---|
memoName | string | the name of the memoized value in the props passed to the wrapped component |
fn | function | the function to invoke to produce the memoized value |
conditions | string[] | names of the properties on the props object react should restrict the firing of the function to |
Example
1import React from 'react'; 2import {compose, withMemo} from '@truefit/bach'; 3 4type Props = { 5 message: string; 6}; 7 8const Component = ({message}: Props) => ( 9 <div> 10 <h1>With Memo</h1> 11 <div> 12 <h2>Message: {message}</h2> 13 </div> 14 </div> 15); 16 17export default compose( 18 withMemo<Props>('message', () => { 19 return 'Hello World'; 20 }), 21)(Component);
1import React from 'react'; 2import {compose, withMemo} from '@truefit/bach'; 3 4const Component = ({message}) => ( 5 <div> 6 <h1>With Memo</h1> 7 <div> 8 <h2>Message: {message}</h2> 9 </div> 10 </div> 11); 12 13export default compose( 14 withMemo('message', () => { 15 return 'Hello World'; 16 }), 17)(Component);
React Hook
An alternative to useState. Accepts a reducer of type (state, action) => newState, and returns the current state paired with a dispatch method.
@truefit/bach will create a dispatchProperty in props with the format ${reducerName}Dispatch
.
Enhancer Signature
Parameter | Type | Description |
---|---|---|
reducerName | string | the name of the reducer value in the props passed to the wrapped component |
reducer | function | the reducer function that conforms to the signature (state, action) => newState |
initialValue | any | the initial value of the reducer |
init | function | a function that returns the initial value of the reducer the 1st time the reducer is invoked. Used for lazy initialization of the reducer. |
Example
1import React, {Dispatch} from 'react'; 2import {compose, withReducer} from '@truefit/bach'; 3 4enum ActionType { 5 INCREMENT = 'INCREMENT', 6 DECREMENT = 'DECREMENT', 7} 8 9type Action = {type: ActionType}; 10 11type Props = { 12 count: number; 13 countDispatch: Dispatch<Action>; 14}; 15 16const Component = ({count, countDispatch}: Props) => ( 17 <div> 18 <h1>With Reducer</h1> 19 <div> 20 <h2>Count: {count}</h2> 21 <button type="button" onClick={() => countDispatch({type: ActionType.INCREMENT})}> 22 Increment 23 </button> 24 <button type="button" onClick={() => countDispatch({type: ActionType.DECREMENT})}> 25 Decrement 26 </button> 27 </div> 28 </div> 29); 30 31const reducer = (state: number, action: Action) => { 32 switch (action.type) { 33 case ActionType.INCREMENT: 34 return state + 1; 35 36 case ActionType.DECREMENT: 37 return state - 1; 38 39 default: 40 return state; 41 } 42}; 43 44export default compose( 45 withReducer<Props, number, Action>('count', reducer, 0) 46)(Component);
1import React from 'react'; 2import {compose, withReducer} from '@truefit/bach'; 3 4const INCREMENT = 'INCREMENT'; 5const DECREMENT = 'DECREMENT'; 6 7const Component = ({count, countDispatch}) => ( 8 <div> 9 <h1>With Reducer</h1> 10 <div> 11 <h2>Count: {count}</h2> 12 <button onClick={() => countDispatch({type: INCREMENT})}> 13 Increment 14 </button> 15 <button onClick={() => countDispatch({type: DECREMENT})}> 16 Decrement 17 </button> 18 </div> 19 </div> 20); 21 22const reducer = (state, action) => { 23 switch (action.type) { 24 case INCREMENT: 25 return state + 1; 26 27 case DECREMENT: 28 return state - 1; 29 30 default: 31 return state; 32 } 33}; 34 35export default compose( 36 withReducer('count', reducer, 0), 37)(Component);
React Hook
Creates a mutable ref object whose .current property is initialized to the passed argument (initialValue). The returned object will persist for the full lifetime of the component.
Enhancer Signature
Parameter | Type | Description |
---|---|---|
refName | string | the name of the ref pointer in the props passed to the wrapped component |
initialValue | any | the initial value of the ref.current |
Example
1import React, {MutableRefObject} from 'react'; 2import {compose, withRef, withCallback} from '@truefit/bach'; 3 4type Props = { 5 textBox1: MutableRefObject<HTMLInputElement>; 6 textBox2: MutableRefObject<HTMLInputElement>; 7 8 focus1: () => void; 9 focus2: () => void; 10}; 11 12const Component = ({textBox1, textBox2, focus1, focus2}: Props) => ( 13 <div> 14 <h1>With Ref</h1> 15 <div> 16 <input ref={textBox1} /> 17 <button type="button" onClick={focus1}> 18 Focus Me 19 </button> 20 </div> 21 <div> 22 <input ref={textBox2} /> 23 <button type="button" onClick={focus2}> 24 Focus Me 25 </button> 26 </div> 27 </div> 28); 29 30export default compose( 31 withRef('textBox1', null), 32 withRef('textBox2', null), 33 34 withCallback<Props>('focus1', ({textBox1}) => () => { 35 textBox1.current.focus(); 36 }), 37 withCallback<Props>('focus2', ({textBox2}) => () => { 38 textBox2.current.focus(); 39 }), 40)(Component);
1import React from 'react'; 2import {compose, withRef, withCallback} from '@truefit/bach'; 3 4const Component = ({textBox1, textBox2, focus1, focus2}) => ( 5 <div> 6 <h1>With Ref</h1> 7 <div> 8 <input ref={textBox1} /> 9 <button onClick={focus1}>Focus Me</button> 10 </div> 11 <div> 12 <input ref={textBox2} /> 13 <button onClick={focus2}>Focus Me</button> 14 </div> 15 </div> 16); 17 18export default compose( 19 withRef('textBox1', null), 20 withRef('textBox2', null), 21 22 withCallback('focus1', ({textBox1}) => () => { 23 textBox1.current.focus(); 24 }), 25 withCallback('focus2', ({textBox2}) => () => { 26 textBox2.current.focus(); 27 }), 28)(Component);
React Hook
Creates a stateful value, and a function to update it.
Enhancer Signature
Parameter | Type | Description |
---|---|---|
stateName | string | the name of the state value in the props passed to the wrapped component |
stateUpdaterName | string | the name of the function in the props passed to the wrapped component that will update state when invoked |
initialValue | any or function | the initial value of the state OR a function that receives props and returns the initial value of the state |
Example
1import React from 'react'; 2import {compose, withState} from '@truefit/bach'; 3 4type Props = { 5 count: number; 6 setCount: (value: number) => void; 7} 8 9const Component = ({count, setCount}: Props) => ( 10 <div> 11 <h1>With State</h1> 12 <div> 13 <h2>Count: {count}</h2> 14 <button onClick={() => setCount(count + 1)}>Increment</button> 15 </div> 16 </div> 17); 18 19export default compose( 20 withState<Props, number>('count', 'setCount', 0) 21)(Component);
1import React from 'react'; 2import {compose, withState} from '@truefit/bach'; 3 4const Component = ({count, setCount}) => ( 5 <div> 6 <h1>With State</h1> 7 <div> 8 <h2>Count: {count}</h2> 9 <button onClick={() => setCount(count + 1)}>Increment</button> 10 </div> 11 </div> 12); 13 14export default compose( 15 withState('count', 'setCount', 0) 16)(Component);
Example (with initialValue function)
1import React from 'react'; 2import PropTypes from 'prop-types'; 3import {compose, withState} from '@truefit/bach'; 4 5type Props = { 6 count: number; 7 setCount: (value: number) => void; 8} 9 10const Component = ({count, setCount}: Props) => ( 11 <div> 12 <h1>With State</h1> 13 <div> 14 <h2>Count: {count}</h2> 15 <button onClick={() => setCount(count + 1)}>Increment</button> 16 </div> 17 </div> 18); 19 20export default compose( 21 withState<Props>('count', 'setCount', () => 0) 22)(Component);
1import React from 'react'; 2import PropTypes from 'prop-types'; 3import {compose, withState} from '@truefit/bach'; 4 5const Component = ({count, setCount}) => ( 6 <div> 7 <h1>With State</h1> 8 <div> 9 <h2>Count: {count}</h2> 10 <button onClick={() => setCount(count + 1)}>Increment</button> 11 </div> 12 </div> 13); 14 15export default compose( 16 withState('count', 'setCount', () => 0) 17)(Component);
React Hook
Allows you to map any hook into an enhancer to use into the compose chain.
Enhancer Signature
Parameter | Type | Description |
---|---|---|
hook | function | the hook you want to use |
parameterValues | any or function | the values that should be passed to they hook as parameters in the order they are to be passed. If you only have one parameter you may just pass the parameter. You may also pass a function to be lazily evaluated and passed props to produce the value |
props | string or string[] | the names of the props returned by the hook. Should be a string if the hook returns an object or value (for example - useMemo), an string[]if the hook returns an array of values (for example - useState), or it may be omitted if the hook has no return value (for example - useEffect) |
Example
1import React, {useState, useMemo, useEffect} from 'react'; 2import {compose, withHook} from '@truefit/bach'; 3 4type Props = { 5 count: number; 6 setCount: (c: number) => void; 7 8 oneMore: number; 9}; 10 11const Component = ({count, setCount, oneMore}: Props) => ( 12 <div> 13 <h1>With Hook</h1> 14 <h2>Count: {count}</h2> 15 <h2>One More: {oneMore}</h2> 16 <div> 17 <button 18 type="button" 19 onClick={() => { 20 setCount(count + 1); 21 }} 22 > 23 + 1 24 </button> 25 </div> 26 </div> 27); 28 29export default compose( 30 withHook<Props>(useState, 0, ['count', 'setCount']), 31 withHook<Props>(useMemo, ({count}: Props) => () => count + 1, 'oneMore'), 32 33 withHook<Props>(useEffect, ({count}: Props) => () => { 34 console.log(`Count ${count}`); // eslint-disable-line 35 }), 36)(Component);
1import React, {useState, useMemo, useEffect} from 'react'; 2import {compose, withHook} from '@truefit/bach'; 3 4const Component = ({count, setCount, oneMore}) => ( 5 <div> 6 <h1>With Hook</h1> 7 <h2>Count: {count}</h2> 8 <h2>One More: {oneMore}</h2> 9 <div> 10 <button onClick={() => { setCount(count + 1); }}>+ 1</button> 11 </div> 12 </div> 13); 14 15export default compose( 16 withHook(useState, 0, ['count', 'setCount']), 17 withHook(useMemo, ({count}) => () => count + 1, 'oneMore'), 18 19 withHook(useEffect, ({count}) => () => { 20 console.log(`Count ${count}`); // eslint-disable-line 21 }), 22)(Component);
Allows you to attach static props to the resultant HOC component. Bach will also copy any static properties defined on the component passed to compose up to the generated HOC.
Enhancer Signature
Parameter | Type | Description |
---|---|---|
props | object | an object containing the key-value pairs to use as static props |
Example
1import React from 'react'; 2import {compose, withStaticProps} from '@truefit/bach'; 3 4const Component = () => ( 5 <div> 6 <h1>With Static Props</h1> 7 </div> 8); 9 10export default compose( 11 withStaticProps({ 12 navigationOptions: { 13 headerTitle: 'Bach', 14 }, 15 }), 16)(Component);
1import React from 'react'; 2import {compose, withStaticProps} from '@truefit/bach'; 3 4const Component = () => ( 5 <div> 6 <h1>With Static Props</h1> 7 </div> 8); 9 10export default compose( 11 withStaticProps({ 12 navigationOptions: { 13 headerTitle: 'Bach', 14 }, 15 }), 16)(Component);
Sometimes it is helpful to be able to group enhancers into a named object that can be used across multiple components in your codebase. To support this, bach exposes the exposes the composeEnhancers function (you could alternatively use a native array, but we think this reads better).
Example
1import React from 'react'; 2import {compose, composeEnhancers, withCallback} from '@truefit/bach'; 3import {withActions, withSelector} from '@truefit/bach-redux'; 4import {withStyles} from '@truefit/bach-material-ui'; 5 6const Component = () => ( 7 <div> 8 <h1>Headline</h1> 9 </div> 10); 11 12const withArticles = composeEnhancers( 13 withActions({loadArticles}), 14 withSelector('articles', articlesSelector), 15); 16 17export default compose( 18 withArticles, 19 withStyles({ 20 container: { 21 width: 100, 22 } 23 }), 24);
1import React from 'react'; 2import {compose, composeEnhancers, withCallback} from '@truefit/bach'; 3import {withActions, withSelector} from '@truefit/bach-redux'; 4import {withStyles} from '@truefit/bach-material-ui'; 5 6const Component = () => ( 7 <div> 8 <h1>Headline</h1> 9 </div> 10); 11 12const withArticles = composeEnhancers( 13 withActions({loadArticles}), 14 withSelector('articles', articlesSelector), 15); 16 17export default compose( 18 withArticles, 19 withStyles({ 20 container: { 21 width: 100, 22 } 23 }), 24);
One of the guidelines mentioned above was to make it easy for others to add enhancers for their own projects. Below are a couple of "additional" libraries that we have developed for other libraries that we commonly use, but didn't want to be a part of the base dependencies.
This enhancer allows you to connect the component to your Redux store.
This enhancer allows you to use the styling HOC withStyles from the React Material UI library in a compositional approach.
This library implements many of the enhancers found in the recompose library that are not tightly tied to react hooks.
We would love to see members of the community add their own enhancers. If you come up with one that is applicable to the larger community (for example, wrapping a different React-CSS framework), please contact us so that we can add it to the list above.
To create your own enhancers, you need to pass a function to the compose method that returns a js object with the required properties. This is typically done as the result of a curried function, you can check the source code of existing enhancers for reference.
Your enhance should follow the following signature:
1type StringKeyCache = {[key: string]: unknown}; 2type ComponentTransform = (component: FunctionComponent) => FunctionComponent; 3 4type EnhancerResult = { 5 dependencies: StringKeyCache; 6 initialize: string; 7 props: string[]; 8 transformComponent?: ComponentTransform; 9}; 10 11type EnhancerContext = { 12 component: ReactNode; 13 generateNewVariable: () => string; 14}; 15 16type Enhancer = (context: EnhancerContext) => EnhancerResult;
Property | Type | Description |
---|---|---|
generateNewVariable | function | a utility function that will generate a random 16 character string that can be used as a variable name in your initialize code. These strings are guaranteed to be unique inside the scope of the single HOC component generated. |
Property | Type | Description |
---|---|---|
dependencies | {[key: string]: unknown} | a map of the dependencies for your enhancer. These will be available to your initialize code by the keys specified. The compose method reduces all keys to a single unique key set |
initialize | string | the code that will be added in line in order to the generated HOC |
props | string[] | the properties that the code creates that need to be added to the overall property object that will be passed to the wrapped component |
transformComponent | (component: FunctionComponent) => FunctionComponent (optional) | a function that is passed the resultant HOC, the function is expected to return an HOC to use |
As mentioned above, we wanted to keep the levels of HOC to a max of one. To accomplish this goal, rather than have a series of functions, we need each enhancer to actually expose the code it requires to work. The compose method combines all of these string of code into a single HOC at runtime. Under the covers, compose uses new Function()
to accomplish this transformation.
Thus there are a couple of important ideas to keep in mind when writing your initialize implementation code:
We welcome contributions. Whether its passing on an idea, adding code, writing your own set of enhancers, or telling us about a bug you found - together we can make this a better tool. Please see the CONTRIBUTING.md for guidelines.
Some Ideas To Get Started:
In closing, we wanted to share some links that had effects on our thinking when putting this library together.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/20 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More