Returns a function that, when called with arguments args
, will return a new wrapper based on the render prop in the original wrapper's prop propName
.
NOTE: can only be called on wrapper of a single non-DOM component element node.
propName
(String
):...args
(Array<Any>
):This essentially calls wrapper.prop(propName)(...args)
.
ShallowWrapper
: A new wrapper that wraps the node returned from the render prop.
class Mouse extends React.Component { constructor() { super(); this.state = { x: 0, y: 0 }; } render() { const { render } = this.props; return ( <div style={{ height: '100%' }} onMouseMove={(event) => { this.setState({ x: event.clientX, y: event.clientY, }); }} > {render(this.state)} </div> ); } } Mouse.propTypes = { render: PropTypes.func.isRequired, };
const App = () => ( <div style={{ height: '100%' }}> <Mouse render={(x = 0, y = 0) => ( <h1> The mouse position is ({x}, {y}) </h1> )} /> </div> );
const wrapper = shallow(<App />) .find(Mouse) .renderProp('render')(); expect(wrapper.equals(<h1>The mouse position is 0, 0</h1>)).to.equal(true);
const wrapper = shallow(<App />) .find(Mouse) .renderProp('render')(10, 20); expect(wrapper.equals(<h1>The mouse position is 10, 20</h1>)).to.equal(true);
© 2015 Airbnb, Inc.
Licensed under the MIT License.
https://airbnb.io/enzyme/docs/api/ShallowWrapper/renderProp.html