Skip to content

Commit

Permalink
refactor: rename withRenderProps to toRenderProps [BREAKING CHANGE]
Browse files Browse the repository at this point in the history
  • Loading branch information
evenchange4 committed May 24, 2018
1 parent 3f3ebf8 commit 8940075
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const PureComponent = pure(BaseComponent)
+ [`getContext()`](#getcontext)
+ [`lifecycle()`](#lifecycle)
+ [`toClass()`](#toclass)
+ [`withRenderProps()`](#withrenderprops)
+ [`toRenderProps()`](#toRenderProps)
* [Static property helpers](#static-property-helpers)
+ [`setStatic()`](#setstatic)
+ [`setPropTypes()`](#setproptypes)
Expand Down Expand Up @@ -565,10 +565,10 @@ Takes a function component and wraps it in a class. This can be used as a fallba
If the base component is already a class, it returns the given component.
### `withRenderProps()`
### `toRenderProps()`
```js
withRenderProps(
toRenderProps(
hoc: HigherOrderComponent
): ReactFunctionalComponent
```
Expand All @@ -578,7 +578,7 @@ Creates a component that accepts a function as a children with the high-order co
Example:
```js
const enhance = withProps(({ foo }) => ({ fooPlusOne: foo + 1 }))
const Enhanced = withRenderProps(enhance)
const Enhanced = toRenderProps(enhance)

<Enhanced foo={1}>{({ fooPlusOne }) => <h1>{fooPlusOne}</h1>}</Enhanced>
// renders <h1>2</h1>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react'
import { mount } from 'enzyme'
import { withRenderProps, defaultProps } from '../'
import { toRenderProps, defaultProps } from '../'

test('withRenderProps creates a component from defaultProps HOC', () => {
test('toRenderProps creates a component from defaultProps HOC', () => {
const enhance = defaultProps({ foo: 'bar' })
const Enhanced = withRenderProps(enhance)
const Enhanced = toRenderProps(enhance)

expect(Enhanced.displayName).toBe('defaultProps(RenderPropsComponent)')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* @flow */

import * as React from 'react'
import { compose, withProps, withRenderProps, withHandlers } from '../..'
import { compose, withProps, toRenderProps, withHandlers } from '../..'
import type { HOC } from '../..'

const enhance: HOC<*, {| +x: number |}> = compose(
Expand All @@ -15,7 +15,7 @@ const enhance: HOC<*, {| +x: number |}> = compose(
})
)

const WithProps = withRenderProps(enhance)
const WithProps = toRenderProps(enhance)

const Comp = () =>
<WithProps x={1}>
Expand Down
2 changes: 1 addition & 1 deletion src/packages/recompose/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export { default as withContext } from './withContext'
export { default as getContext } from './getContext'
export { default as lifecycle } from './lifecycle'
export { default as toClass } from './toClass'
export { default as withRenderProps } from './withRenderProps'
export { default as toRenderProps } from './toRenderProps'

// Static property helpers
export { default as setStatic } from './setStatic'
Expand Down
2 changes: 1 addition & 1 deletion src/packages/recompose/index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ declare export function createEventHandler(): {
handler: Function,
}

declare export function withRenderProps<B, E>(
declare export function toRenderProps<B, E>(
hoc: HOC<B, E>
): React$ComponentType<{|
...$Exact<E>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function withRenderProps(hoc) {
export default function toRenderProps(hoc) {
const RenderPropsComponent = props => props.children(props)
return hoc(RenderPropsComponent)
}

0 comments on commit 8940075

Please sign in to comment.