Skip to content

Commit d932b12

Browse files
authored
Update README.md
1 parent 10578d7 commit d932b12

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1+
NOTE: I created this tool, but this is basically an inferior version of [Unstated](https://github.com/jamiebuilds/unstated) that you should use instead. If you need an HOC for unstated you can create one easily on top of the render prop api:
2+
3+
```js
4+
export const connectContainer = (
5+
Container,
6+
mapContainerToProps = () => null,
7+
) => WrappedComponent => {
8+
const PureWrappedComponent = pure(WrappedComponent);
9+
const ConnectedComponent = ownProps => (
10+
<Subscribe to={[Container]}>
11+
{container => {
12+
const mappedProps = mapContainerToProps(container, ownProps);
13+
//console.debug('mappedProps', mappedProps, container);
14+
return (
15+
<PureWrappedComponent
16+
{...mappedProps}
17+
{...ownProps} // own props can always overrides connected props
18+
/>
19+
);
20+
}}
21+
</Subscribe>
22+
);
23+
24+
ConnectedComponent.displayName = `connectContainer(${getDisplayName(
25+
WrappedComponent,
26+
)})`;
27+
28+
return ConnectedComponent;
29+
};
30+
```
31+
32+
33+
134
React Updatable Context
235
==========================
336

0 commit comments

Comments
 (0)