Search code examples
reactjstypescriptsvg

React svg xmlns:xlink identifier expected


How do I fix the identifier expected error when using typescript, react, and svgs?

return (
    <svg version="1.1" xmlns="http://www.w3.org/2000/svg" 
                   xmlns:xlink="http://www.w3.org/1999/xlink" >
         <defs> ... </defs>
         <use ... xlink:href="#path-1"/>
    </svg>
);

Solution

  • Use the react specific spelling (JSX) for each attribute, for example:

    return (
        <svg version="1.1" xmlns="http://www.w3.org/2000/svg" 
                       xmlnsXlink="http://www.w3.org/1999/xlink" >
             <defs> ... </defs>
             <use ... xlinkHref="#path-1"/>
        </svg>
    );
    
    • xmlnsXlink
    • xlinkHref

    also see: