Skip to content

Commit

Permalink
Fixes #84 - Support ref using React.forwardRef
Browse files Browse the repository at this point in the history
  • Loading branch information
iamhosseindhv committed Apr 8, 2019
1 parent e87e83d commit 5dff56c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/withSnackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import getDisplayName from './utils/getDisplayName';
import SnackbarContext from './SnackbarContext';

const withSnackbar = (Component) => {
const WrappedComponent = props => (
const WrappedComponent = React.forwardRef((props, ref) => (
<SnackbarContext.Consumer>
{context => (
<Component
{...props}
ref={ref}
enqueueSnackbar={context.handleEnqueueSnackbar}
closeSnackbar={context.handleCloseSnackbar}
/>
)}
</SnackbarContext.Consumer>
);
));

if (process.env.NODE_ENV !== 'production') {
WrappedComponent.displayName = `WithSnackbar(${getDisplayName(Component)})`;
Expand Down

0 comments on commit 5dff56c

Please sign in to comment.