Skip to content

Commit e9a47be

Browse files
committed
Added "mapContextToProps" to "withSearch"
This is so that we have a hook into state so that we can transform data before passing them on as props to a component. Helpful if you want to do something like apply a custom sort to data, etc.
1 parent a5af669 commit e9a47be

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/search-lib/withSearch.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ import SearchConsumer from "./SearchConsumer";
66
* This is a Higher Order Component that is used to expose (as `props`) all
77
* state and Actions provided by the SearchProvider to "container"
88
* components.
9+
*
10+
* `mapContextToProps` can be used to manipulate actions and state from context
11+
* before they are passed on to the container.
912
*/
1013
export default function withSearch(Component) {
1114
return function(props) {
15+
const { mapContextToProps = context => context, ...rest } = props;
16+
1217
return (
1318
<SearchConsumer>
14-
{context => <Component {...context} {...props} />}
19+
{context => <Component {...mapContextToProps(context)} {...rest} />}
1520
</SearchConsumer>
1621
);
1722
};

0 commit comments

Comments
 (0)