react-with-context
Version:
Pass context into React components and replace for React.withContext
37 lines (24 loc) • 866 B
Markdown
WithContext passes a specified context object to its child components. This is useful when writing unit tests for React components.
You can use it to replace `React.withContext`, which was removed in React 0.14.
```jsx
<WithContext context={context}>
<ExampleComponent />
</WithContext>
```
Or, including import and rendering with TestUtils:
```jsx
import WithContext from "react-with-context"
const context = { greeting: "Hello" };
TestUtils.renderIntoComponent(
<WithContext context={context}>
<ExampleComponent />
</WithContext>
);
```
[](https://github.com/mattzeunert/react-with-context-demo)
> npm install react-with-context --save-dev
Use `babel --out-file WithContext.dist.js src/WithContext.js` to compile the component. Then run `npm test`.