Switching to use forwardRef
This commit is contained in:
@@ -34,15 +34,14 @@ const render = (data, extraProps) => {
|
||||
children.length === 1 ? children[0] : children);
|
||||
};
|
||||
|
||||
const SVG = ({ data, imageRef: ref }) => render(data, { ref });
|
||||
const SVG = React.forwardRef(({ data }, ref) => render(data, { ref }));
|
||||
|
||||
SVG.propTypes = {
|
||||
data: PropTypes.shape({
|
||||
type: PropTypes.oneOf(Object.keys(nodeTypes)).isRequired,
|
||||
props: PropTypes.object,
|
||||
children: PropTypes.array
|
||||
}).isRequired,
|
||||
imageRef: PropTypes.func
|
||||
}).isRequired
|
||||
};
|
||||
|
||||
export default SVG;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import React from 'react';
|
||||
import { shallow, mount } from 'enzyme';
|
||||
import { shallow } from 'enzyme';
|
||||
|
||||
import SVG from 'components/SVG';
|
||||
import Pin from './Pin';
|
||||
|
||||
describe('SVG', () => {
|
||||
test('rendering', async () => {
|
||||
@@ -94,16 +93,4 @@ describe('SVG', () => {
|
||||
);
|
||||
expect(component).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('imageRef prop', () => {
|
||||
let image;
|
||||
const imageRef = element => image = element;
|
||||
const data = {
|
||||
type: 'Pin'
|
||||
};
|
||||
mount(
|
||||
<SVG data={ data } imageRef={ imageRef }/>
|
||||
);
|
||||
expect(image).toBeInstanceOf(Pin);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user