Comments (4)
Oh, that's a cool library! I haven't put a huge amount of thought into animations yet, partially because I simply don't need them but also because I was confident that there would be a great React way of doing it.
The bottom line is that we can't use D3s transitions because they involve timeouts and state, which obviously doesn't work unless tightly integrated into React.
This approach looks great and should work fine. I haven't tried it but this should work.
function renderBox(interpolated) {
// Create your element.
var el = ReactFauxDOM.createElement('div')
el.style.setProperty('color', 'red')
el.setAttribute('class', 'box')
el.setAttribute('transform', `translate3d(${interpolated.val}px, 0, 0)`)
return el.toReact()
}
return (
<Spring defaultValue={{val: 0}} endValue={{val: this.state.open ? 400 : 0}}>
{interpolated =>
{renderBox(interpolated)}
}
</Spring>
)
Because it returns react elements you can return the result of el.toReact()
into any part of a React tree. This should work beautifully!
An addition to react-faux-dom that would make this even better would be allowing you to perform el.appendChild
etc with functions or React components that are yet to be instantiated. So you could call createElement(Spring)
, modify it, add a child div with properties and then render it.
Not sure how you'd get the interpolated value though, it looks like you need to set the Spring
elements children array to a function. The example I gave should do the trick though :)
I'd love to know if this works well for you or not. Animations have been playing on my mind.
from react-faux-dom.
Thank you for response. But the code does not work.
Uncaught Error: Invariant Violation: Spring.render(): A valid ReactComponent must be returned. You may have returned undefined, an array or some other invalid object.
from react-faux-dom.
actually we do not need { } in
{interpolated =>
{renderBox(interpolated)}
}
the following works
{interpolated =>
renderBox(interpolated)
}
Thank you very much. @Olical
renderChart : function(interpolated){
var el = ReactFauxDOM.createElement('div');
el.style.setProperty('backgroundColor', 'red')
el.setAttribute('class', 'button')
el.style.setProperty('height', '50px')
el.style.setProperty('border','border:5px solid red')
el.style.setProperty('width', `${interpolated.val}` + "px")
return el.toReact()
},
render:function() {
return (
<Spring defaultValue={{val: 0}} endValue={{val: 800 }}>
{interpolated =>
this.renderChart(interpolated)
}
</Spring>
)
}
from react-faux-dom.
I didn't get a notification for this (that's been happening a lot recently!) but that's excellent. I hope it's working well for you. Do you get a smooth experience?
Also you can set style using a full inline style string now, like these new tests. I think you can just set an object too. Just a heads up :)
from react-faux-dom.
Related Issues (20)
- Append StyledComponents by d3? HOT 4
- 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.