Comments (10)
fyi: ES6 modules not support mixins today so as a component it is still working with React 0.13 and ES6 class components : https://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html
from react-visibility-sensor.
I'm a little confused, why would how vanilla ES6 works matter for code that is specifically for use with React? Mixings are a core functionality of React, regardless of whether you author it using ES5 or ES6.
from react-visibility-sensor.
Hi @Pomax sorry for the delay replying. I'm not sure I see the advantage here in making this a mixin, even in the example you could do the same thing just as easily by calling setState({ visible })
in the onChange
callback.
Having a the VisibilitySensor as a totally separate component can give better separation of concerns, since with mixins you end up with a lot of hidden magical stuff in your component.
Do you have other ideas on benefits of making this a mixin? I'm open to it if there are.
from react-visibility-sensor.
mostly the "I need that magic, instead of having to wrap everything in more and more components". When things are done as components, you end up with stuff like this:
...
render: function() {
return (
<Draggable onChange={this.handleDragChange}>
<VisibilitySensor onChange={this.handleVisibilityChange}>
<OAuth onChange={this.handleOAuthChange}>
<...>
<finally my own stuff>
</...>
<//OAuth>
</VisibilitySensor>
</Draggable>
);
},
...
It gets incredibly unwieldy very fast, as opposed to:
module.exports = React.createClass({
mixins: [
require("react-draggable"),
require("react-visibility-sensor"),
require("react-oauth),
...
],
...
render: function() {
return <just my stuff. The mixins already tell me what's tacked on />;
},
handleDragChange: function(...) { ... },
handleVisibilityChange: function(...) { ... },
handleOAuthChange: function(...) { ... },
...
});
from react-visibility-sensor.
Sure, I can see how this gets messy. Out of curiosity is there any reason why VisibilitySensor
needs to be wrapping the other components? Could you do your rewrite as:
module.exports = React.createClass({
mixins: [
require("react-draggable"),
require("react-oauth),
...
],
...
render: function() {
return (
<VisibilitySensor onChange={this.handleVisibilityChange} />
<just my stuff. The mixins already tell me what's tacked on />
)
},
handleDragChange: function(...) { ... },
handleVisibilityChange: function(...) { ... },
handleOAuthChange: function(...) { ... },
...
});
Or is there a certain behaviour you need that only occurs when there is wrapping / nesting?
from react-visibility-sensor.
Unfortunately React only lets you have a single top level element (since it's actually just syntactic sugar around a JS object creation call), so you'd still have (at the very least):
render: function() {
return (
<div>
<VisibilitySensor onChange={this.handleVisibilityChange} />
<just my stuff. The mixins already tell me what's tacked on />
</div>
)
},
from react-visibility-sensor.
Right, forgot about that bit :) Would you consider that a solution? Or still not acceptable?
from react-visibility-sensor.
I suppose that would work, it's less crazy than the nesting at least =)
from react-visibility-sensor.
Cool. Sorry for all the push-back too btw :) It's mostly that I'm just curious to know how to solve these problems without taking on the hidden costs of mixins. That said, I will gladly accept a PR to add mixinification (provided that none of the current functionality is affected).
from react-visibility-sensor.
pushback surfaces the important data, never stop =)
from react-visibility-sensor.
Related Issues (20)
- Link Anchor Not Working
- trigger when it reaches a certain section of the viewport/containment HOT 1
- How to keep elements visible after first scroll HOT 4
- Use requestAnimationFrame
- Containment as a RefObject HOT 2
- onChange is not triggered when required component reaches viewport HOT 2
- No Init check for visibility ?
- No handler for determining visibility of elements that never change visibility
- Deprecation Error with React.StrictMode HOT 5
- Is this project dead? HOT 6
- Error when dispatching on load
- Visibility sensor is not capturing when the first element's top section is in view
- Calling onChange in one element when another element goes out of view
- Is project abandoned? HOT 1
- You should update the readme:
- does not match the corresponding path on disk `react`.
- VisibilitySensor doesn't fire on smaller devices
- Warning: findDOMNode is deprecated in StrictMode HOT 4
- Cannot read properties of undefined (reading 'Component')
- TS2694: Namespace 'React' has no exported member 'StatelessComponent'
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-visibility-sensor.