Jump to content
Search Community

SVG line rotation in Reactjs

DiegoM test
Moderator Tag

Recommended Posts

Hello! I'm creating random triangles.

image.png.69c4254645d1bf93e26e97967ceca27a.png
For the exterior angle I'm using an svg Line, the thing is that I'm passing the center of rotation as a prop to a react component, but the rotation works well just the first time.

 

This is the component:
 

const LineExtension = ({centerX, centerY, rotation, length}) => {

    let [tl] = useState(gsap.timeline())

    useEffect(() => {
        tl.to(`#line`, {rotation: -rotation, svgOrigin: `${centerX} ${centerY}`})
    }, [centerX, centerY, rotation, tl])

    return (
        <g
            >
            <line
                id="line"
                x1={centerX} y1={centerY} x2={centerX+length} y2={centerY} style={{stroke: "rgb(255,0,0)", strokeWidth:"1"}}
            />
        </g>
    );
};

Hope you can help me, thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...