question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for svg in React code.

See original GitHub issue

Issuehunt badges

Supporting inline SVG

React by default can support inline svg code. Because NodeGUI does not render to a browser window though, we can’t use that.

Possible Solutions One solution might be to bridge QTSvg albeit I am not savvy enough to do this.

Sample code that triggered error

import React from 'react';
import { letterFrequency } from '@vx/mock-data';
import { Group } from '@vx/group';
import { Bar } from '@vx/shape';
import { scaleLinear, scaleBand } from '@vx/scale';

const data = letterFrequency;

const width = 500;
const height = 500;
const margin = { top: 20, bottom: 20, left: 20, right: 20 };

const xMax = width - margin.left - margin.right;
const yMax = height - margin.top - margin.bottom;

const x = (d: any) => d.letter;
const y = (d: any) => +d.frequency * 100;

const xScale = scaleBand({
  rangeRound: [0, xMax],
  domain: data.map(x),
  padding: 0.4,
});
const yScale = scaleLinear({
  rangeRound: [yMax, 0],
  domain: [0, Math.max(...data.map(y))],
});

const compose = (scale: any, accessor: any) => (data: any) => scale(accessor(data));
const xPoint = compose(
  xScale,
  x,
);
const yPoint = compose(
  yScale,
  y,
);

function BarGraph() {
  return (
    <svg width={width} height={height}>
      {data.map((d: any, i: any) => {
        const barHeight = yMax - yPoint(d);
        return (
          <Group key={`bar-${i}`}>
            <Bar x={xPoint(d)} y={yMax - barHeight} height={barHeight} width={xScale.bandwidth()} fill="#fc2e1c" />
          </Group>
        );
      })}
    </svg>
  );
}
export default BarGraph;
``


<!-- Issuehunt content -->

---

<details>
<summary>
<b>IssueHunt Summary</b>
</summary>


### Backers (Total: $20.00)

- $20.00 have been anonymously funded.

#### [Become a backer now!](https://issuehunt.io/r/nodegui/react-nodegui/issues/31)
#### [Or submit a pull request to get the deposits!](https://issuehunt.io/r/nodegui/react-nodegui/issues/31)
### Tips

- Checkout the [Issuehunt explorer](https://issuehunt.io/r/nodegui/react-nodegui/) to discover more funded issues.
- Need some help from other developers? [Add your repositories](https://issuehunt.io/r/new) on IssueHunt to raise funds.
---
IssueHunt has been backed by the following sponsors. [Become a sponsor](https://issuehunt.io/membership/members)
</details>
<!-- /Issuehunt content-->

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:6
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
a7ulcommented, Dec 29, 2019

Let me know if you face any issue regarding QPainter or wrapping any component in React. I can help out!

1reaction
Ty3uKcommented, Dec 25, 2019

@danedavid yep, you’re right. In my plugin I want to implement those elements in next step 😃 Also i’ve tried to use react-dom/server package to simply render components to string, but this approach not worked (crashes inside qode environment).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use SVGs in React - LogRocket Blog
SVGs can be imported and used directly as a React component in your React code. The image is not loaded as a separate...
Read more >
React SVG: How to use SVGs best in React - CopyCat Blog
Another way to import SVG in react with full control of its customization is by converting the regular SVG tags to react SVG...
Read more >
How to use SVGs in React | Sanity.io guide
This article will explore how to use SVG in React in three examples. ... Include SVGs directly in JSX. JSX supports all SVG...
Read more >
How to Import SVGs in a React and Vite app - freeCodeCamp
JSX supports the svg tag, so we can copy-paste the SVG directly into our React components. This method is straightforward as it helps...
Read more >
How to display svg icons(.svg files) in UI using React ...
I have seen code which talk about bring the svg code into react rather than using the .svg icon as image and show...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found