Comments (4)
- Use
stateless components
as possible as you can - Use React.Component if you can't (specially when we've event handlers)
- Avoid
React.createClass()
from mantra.
I hope we can close this.
from mantra.
Apologies for re-opening this old thread.
However, I've got some troubles related to the topic.
In short, I'm trying to implement a simple dialog
from the Material-UI library.
Link: http://www.material-ui.com/#/components/dialog
- If I use
stateless components
, then I have to store state in LocalState. Which is OK, but whenever I change anything in LocalState, everything re-renders. Even with only a few elements - 4 to be exact, this is noticeably slower. Also, using this approach becomes a nightmare when trying to use react-storybook. - If I use
React.Component
, then either there are parse errors from official examples, or this.setState() is undefined if I use constructor(). I've googled all the relevant errors, and applied all the suggested fixes (using .bind() et. al), to no avail. - If I use
React.createClass
, then everything works! There are no multiple re-renders nor laggy-interface. Using it with react-storybook is a dream. It just works.
So, I have to ask, @arunoda:
- Why should I avoid React.createClass?
- How would you implement the state management needed for the element from Material-UI?
I'm a beginner and I'm sincerely eager to learn.
Thanks for all your hard work.
Really looking forward to your answer.
Regards,
Nadeeem
from mantra.
here is a simple example of React.Component
:
class Checkbox extends React.Component {
constructor(props) {
super(props);
this.state = {
checked: props.defaultValue,
};
this.handleValuesChange = this.handleValuesChange.bind(this);
}
handleValuesChange() {
const state = {
checked: !this.state.checked,
};
this.setState(state);
this.props.onChange(state);
}
render() {
return <div>
<label>
<input type="checkbox" onChange={this.handleValuesChange} checked={this.state.checked}/> email
</label>
</div>;
}
}
from mantra.
Related Issues (20)
- Correct Way to Install a Bootstrap Theme? HOT 3
- Controllers and server-side context HOT 3
- Where is the best place to put your initial states with Reactive Dict/Local State HOT 1
- Unable to sign up /login on Mantra talk HOT 4
- should we use sub-manager for mantra ? HOT 2
- A linter for Mantra
- Accounts.onPasswordResetLink .... where??
- Dead link for Mantra live demo HOT 2
- Support Apollo HOT 1
- Meteor/MiniMongo is Local State HOT 1
- Global Subscription HOT 6
- Issue with re-rendering on Google Chrome Android (Moblie)
- Meteor methods in lib folder HOT 1
- Problem with Routing and Alert
- More intuitive react component naming convention HOT 4
- Ability to module-namespace actions HOT 13
- Issue with Mobile HOT 1
- how to get REF of containers component
- Clarify module meaning HOT 5
- Problems with @storybook/mantra-core and react-komposer@2 HOT 1
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 mantra.