Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Instead, it *returns* a new, connected component class, for you to use.
* [`options`] *(Object)* If specified, further customizes the behavior of the connector.
* [`pure = true`] *(Boolean)*: If true, implements `shouldComponentUpdate` and shallowly compares the result of `mergeProps`, preventing unnecessary updates, assuming that the component is a “pure” component and does not rely on any input or state other than its props and the selected Redux store’s state. *Defaults to `true`.*
* [`withRef = false`] *(Boolean)*: If true, stores a ref to the wrapped component instance and makes it available via `getWrappedInstance()` method. *Defaults to `false`.*
* [`displayName = 'Connect'`] *(String)*: Custom display name for the generated wrapper component. This can been seen in the React Devtools and in warning messages. *Defaults to `'Connect'`.*

#### Returns

Expand Down
4 changes: 2 additions & 2 deletions src/components/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
}

const finalMergeProps = mergeProps || defaultMergeProps
const { pure = true, withRef = false } = options
const { pure = true, withRef = false, displayName = 'Connect' } = options
const checkMergedEquals = pure && finalMergeProps !== defaultMergeProps

// Helps track hot reloading.
const version = nextVersion++

return function wrapWithConnect(WrappedComponent) {
const connectDisplayName = `Connect(${getDisplayName(WrappedComponent)})`
const connectDisplayName = `${displayName}(${getDisplayName(WrappedComponent)})`

function checkStateShape(props, methodName) {
if (!isPlainObject(props)) {
Expand Down
11 changes: 11 additions & 0 deletions test/components/connect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1868,5 +1868,16 @@ describe('React', () => {

ReactDOM.unmountComponentAtNode(div)
})

it('should allow custom displayName', () => {
@connect(null, null, null, { displayName: 'Custom' })
class MyComponent extends React.Component {
render() {
return <div></div>
}
}

expect(MyComponent.displayName).toEqual('Custom(MyComponent)')
})
})
})