Comments (4)
I'm not sure what you mean exactly. There's nothing in ReactFauxDOM to do what you have shown, so I presume it's another library for creating styled nodes?
I think you may just have to use CSS since I haven't done anything like this. Maybe try some things out and see what you get 😄
from react-faux-dom.
Sorry to be ambiguous, I just want to do this:
// these two example will work:
// append some reace element
const svg1 = select(faux).append('svg')
svg1.append(() => <circle
className="path"
cx="25"
cy="25"
r="20"
/>)
// Above has the same effect as below
const svg2 = select(faux).append('svg')
svg2
.append('circle')
.attr('cx', 25)
.attr('cy', 25)
.attr('r', 20);
But now, if I append a react element, and trying to append something to that react element, error saying this.appendChild is not a function
will be thrown:
// this can't work
const svg3 = select(faux).append(() => <svg />)
svg3
.append('circle')
.attr('cx', 25)
.attr('cy', 25)
.attr('r', 20);
// though this will not throw:
const svg4 = select(faux).append(() => <svg />)
What happened to this.appendChild
? So I couldn't add a react element to faux?
from react-faux-dom.
appendChild
does exist, so I would check what this
is at that point. Maybe it's not what you expect.
Oh, I just realised that you can't do that last example though, no. You can put a React tree inside of a FauxDOM tree, but you can't then append children to the React tree because it's React.
You're doing something like this: Faux -> Append React child -> Append Faux child to React child.
React does not support mutation like this, you should just use FauxDOM nodes if you wish to mutate their children, which is what you're doing. The FauxDOM only supports React nodes at the leaves of your tree, ideally everything would be FauxDOM nodes in the tree though, that's what it was designed for.
Build your Faux DOM tree, turn it into a React tree when you're done. Embedding React in the Faux DOM tree was an afterthought just in case someone needed to do it.
from react-faux-dom.
Thanks for explaining it, it's reasonable.
instead of traditional d3 way:
const svg = select(faux).append('svg')
svg
.append('circle')
.attr('cx', 25)
.attr('cy', 25)
.attr('r', 20);
The advantage of appending React child is that we can do:
const Circle = styled.circle`
cx: ${props => props.cx};
cy: ${props => props.cy};
r: ${props => props.r};
`;
const svg = select(faux).append(() => <svg />)
svg.append(() => <Circle cx={25} cy={25} r={5} />)
But the React way, Other than being fancy and state of art, well, that's actually not so convenient...Just looks cool.
from react-faux-dom.
Related Issues (20)
- Cannot append 'svg' properly with 'ReactFauxDOM' HOT 8
- Is it possible to get the stringified DOM? HOT 3
- Uncaught TypeError: (0 , _reactFauxDom.withFauxDOM) is not a function HOT 2
- Limitations HOT 2
- dangerouslySetInnerHTML - How can I set it? HOT 8
- getComputedTextLength() of a faux-element HOT 1
- Circle radius is NaN if adding d3 enter. HOT 9
- Failed to execute 'querySelector' on 'Document': '[object Object]' is not a valid selector. HOT 2
- Expose component propTypes and defaultProps.
- Expose component propTypes and defaultProps. HOT 2
- README may need update HOT 2
- TypeError: "text.node(...).getBBox is not a function" HOT 1
- Duplicate tick labels on axis update HOT 2
- d3.select(...).clone() report error HOT 2
- consider copy static properties to withFauxDOM HOC? HOT 1
- TypeError: node.compareDocumentPosition is not a function HOT 3
- minify react-faux-dom HOT 2
- Integrating React and d3.js with ReactFauxDOM displaying nothing on screen HOT 1
- componentWillMount deprecation HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-faux-dom.