Skip to content

Commit

Permalink
Pass through refs and props to all layers of AsyncCreatable.
Browse files Browse the repository at this point in the history
This enables users of AsyncCreatable to hook the Select which is
created and/or access it as a ref.

Previously there was no way to get at the underlying Select if
you used AsyncCreatable.
  • Loading branch information
DanielHeath committed Nov 9, 2016
1 parent d216b56 commit 2d3c063
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions src/AsyncCreatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,42 @@ const AsyncCreatable = React.createClass({
render () {
return (
<Select.Async {...this.props}>
{(asyncProps) => (
<Select.Creatable {...this.props}>
{(creatableProps) => (
<Select
{...asyncProps}
{...creatableProps}
/>
)}
{({ref, ...asyncProps}) => {
const asyncRef = ref
return <Select.Creatable {...asyncProps} >
{({ref, ...creatableProps}) => {
const creatableRef = ref
return this.props.children({
...creatableProps,
ref: (select) => {
creatableRef(select)
asyncRef(select)
this.select = select
}
})
}}
</Select.Creatable>
)}
}}
</Select.Async>
);
}
});

function defaultChildren (props) {
return (
<Select {...props} />
);
};

const propTypes = {
children: React.PropTypes.func.isRequired, // Child function responsible for creating the inner Select component; (props: Object): PropTypes.element
}

const defaultProps = {
children: defaultChildren,
}

Async.propTypes = propTypes;
Async.defaultProps = defaultProps;

module.exports = AsyncCreatable;

0 comments on commit 2d3c063

Please sign in to comment.