score:26
In react the attributes form of linear gradient are a bit different and supposed to be like this:
<linearGradient
id="linear-gradient"
gradientUnits="userSpaceOnUse"
x1="1041.6901"
y1="169.485"
x2="1383.9301"
y2="169.485"
gradientTransform="matrix(1 0 0 -1 -761.14 398.97)"
>
<stop offset="14%" stopColor="#2f343b" stopOpacity="0%" />
<stop offset="43%" stopColor="#337082" stopOpacity="41%" />
<stop offset="67%" stopColor="#369fb9" stopOpacity="73%" />
<stop offset="79%" stopColor="#37b1cf" stopOpacity="85%" />
</linearGradient>
It mean that the syntax should be from stop-color
=> stopColor
offset should be in percentage
ReactJs + svg
score:0
Might not be entirely useful but if you have load more than one SVG, ensure the linearGradient id is unique. In my case before, both linearGradient id is id="linear-gradient" , thus the 2nd SVG is actually following the 1st SVG gradient.
score:1
For anyone passing by: another reason for a gradient not working is if its ID contains non-ASCII caracters (like "é"). Happened to me because Adobe Xd was exporting it with ID "Dégradé_par_defaut", which means default_gradient in french :)
score:6
For others coming here later, style={{fill:'url(#linear-gradient)'}}
is unnecessary for just one or a mere few styles. Instead, simplify to fill="url(#linear-gradient)"
. The same applies to other common SVG styling like stroke="url()"
.
Source: stackoverflow.com
Related Query
- React.js - use svg linear gradient not working
- React Native svg clip path on image not working
- React OnMouseDown event is not working whereas OnMouseUp is working fine.(on SVG elements)
- Importing SVG as React component not working with Next.js
- Why is SVG textPath not working in Firefox when rendered by React
- I am trying to use the react hook useContext() but its not working
- React set value to select not working but use selected in option is fine
- Swiper Slider pagination/navigation not working when I use swiper effect in React Js
- Use serverless function to findById in MongoDB Database via Mongoose, and render result in React form - not working
- Image path not working in React as I tried to use use Image path inside an object which is also inside of an array
- How to use the react spring hook with react. Basic code not working
- Polygon mask SVG image not working for tsparticles in React
- Trying to use local-storage in react app, however not working in between pages
- React Accessible SVG Chart: aria-activedescendant not working
- Routes not working in react even when trying to use Routes and Router
- Linear Gradient CSS Not Working in ReactJS
- How do you use state variables to make a nested drag and drop in React / Kanban board not working in React
- Create a react app and use a npm start command but it is not working
- conic gradient css not working in React for unknown reason
- React JS Nested elements both use same onClick event and child event is not working
- Objects are not valid as a React child. If you meant to render a collection of children, use an array instead
- onKeyDown event not working on divs in React
- When should you NOT use React memo?
- You should not use Route or withRouter() outside a Router when using react-router 4 and styled-component in react
- React colspan not working
- React router private routes / redirect not working
- proxy not working for react and node
- lodash debounce in React functional component not working
- React Router v4 routes not working
- React Router v4 Redirect not working
More Query from same tag
- React Rails: Rendering an html.erb file in React js.jsx
- How to disable grouping on one column in react-table V7
- Calling an API fails when deployed with Netlify, works fine when served locally (Reactjs website)
- How to apply media query in Gatsby site?
- Skip stepper connecting lines with CSS
- Multiple properties in ReactJS inlined styles object?
- How to Position a React Native Button at the bottom of my screen to work on multiple ios devices
- React - Log in submit button to render new page
- How to GET limited data from server using axios?
- Django cors not enable?
- How to make Puppeteer work with a ReactJS application on the client-side
- How to see updated list without refreshing the page
- How to remove the previous screen on the tab navigator - React Navigation v5
- React.js throttle mousemove event keep throwing event.persist() error
- Switching Reactstrap NavItem programmatically
- Rendering every iteration of an array sort in React
- Using Material-UI(React) Button with CSS, "select all immediate children" doesn't seem to work
- How do I pass props from Child to Parent in React for incremental onClick?
- How to call functional child component method from class parent component
- How do I control multiple checkboxes in React?
- React / Redux TypeError: Cannot call a class as a function
- Typescript JSDoc ...Rest type syntax
- How do you publish a gatsby project with gatsby-image on Netlify?
- change styles dynamically with react memo
- Why setState crashes browser
- TypeError: Cannot read property 'map' of undefined in React Map
- React - Element reference is undefined in onLoad call
- Pass index as state to component using React
- How to close dropdown menu using own useOnOutsideClick hook?
- How to use React with PowerBI custom visual