Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to get a ref to a dynamically loaded SVG? #171

Open
jwlusby opened this issue Feb 6, 2020 · 1 comment
Open

Is it possible to get a ref to a dynamically loaded SVG? #171

jwlusby opened this issue Feb 6, 2020 · 1 comment

Comments

@jwlusby
Copy link

jwlusby commented Feb 6, 2020

I'm trying to manipulate elements within the dynamically loaded SVG.

Previously I was doing this by importing my svg as a Component, assigning it a ref, then later on, retrieving it by the ref and manipulating child elements within the svg. Something like this:

import { ReactComponent as MySvg} from './my-svg.svg';
import * as d3 from 'd3'

export class SvgDemo extends React.Component {
    constructor(props) {
        super(props);
        this.state = { };
    }

    render() {
        return (<MySvg ref="mySvgRef" />)
    }

    componentDidMount() {        
        var mySvg= d3.select(this.refs.mySvgRef);

        // Manipulate svg components
        // ...
        // ...
    }
}

I was attempting to add 'react-svg-pan-zoom' into the mix by following the example here: https://github.com/chrvadala/react-svg-pan-zoom/blob/master/docs/svg-dynamically-loaded.md

But I can't seem to get at the contents of the loaded svg to manipulate them.

Any help would be really appreciated!

@lionkeng
Copy link
Contributor

Can you provide a code snippet for what you are trying to do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants