Created by: GasimGasimzada
This pull request adds "ref" option to SVGR loader; so that, the root svg
component ref can be accessed. The way it works is that SVGR creates a forward ref and passed the ref to svg component using svgRef
prop.
Example:
import React, { Component } from 'react';
import { ReactComponent as Logo } from './logo.svg'; // CRA default logo file
class App extends Component {
myRef = React.createRef();
componentDidMount() {
console.log(this.myRef);
}
render() {
return (<Logo svgRef={this.myRef} />);
}
}
This example will print the svg element.
Testing
I have added unit tests to webpack/SVGComponent.js; however, I was not able to perform the test. yarn e2e:docker -- --test-suite kitchensin
kept giving me permission denied error inside the container.