Comments (1)
Conversation that happened around this:
Farhan: Hey team so on my ticket the second part indicates that I create a constructor for each component that uses state however, one of the key uses of property initializers is to not use the constructor so as to have readable components. the other advantage is that We can use arrow functions for custom component methods (and avoid having to bind this). https://www.fullstackreact.com/articles/use-property-initializers-for-cleaner-react-components/
John Paul: We need the constructor to allow us to initialize the constructor of the base class (React.Component
) so that we can use this.*
in the constructor. This would come in handy when you need to store the props in the state.
Farhan: First of all we should not store props in the state reason being that when ever the props of the component changes with-out the component being refreshed….the new prop will never be displayed cause the constructor function will never update the current state of the component.
Joy: Using the class constructor does not in anyway prevent you from using arrow functions.
Why the constructor
is important is that we could initialise many other things like what John said
E.g I can store props in state and therefore be able to do some stuff on the props if they need refactoring in that component https://reactjs.org/docs/react-component.html#constructor
Just an example:
constructor() {
super();
this.state = {
printed: props.printed
};
componentWillReceiveProps(nextProps) {
this.setState({
printed: nextProps.printed
})
}
}
Using this.state={} is readable but for class-based components it ties the number of things you can do. It might work at first but in the long run leads to unwanted consequences check react blog post I just sent.
from andela-societies-frontend.
Related Issues (20)
- Choose between <double-qoutes> or <single-qoutes> HOT 2
- If there is no token should be redirected to login page
- Setup Redux
- Setup routing React Router 4
- Create view of the sign in page
- Add ability to sign in
- Fix comment for PageHeader PropType
- Create a config file for different environments.
- Add ability to logout
- Fix bug in router
- Add a component that displays my statistics on the "MyActivities" page.
- Fix deployment errors HOT 1
- Resolves #155907023 A logged in user should be able to see their profile picture
- Resolves #155906765
- Create a society page component. Resolves #156307063
- Create the Redemptions page component Resolves #156309348
- Resolves [#156801312] As a logged in user as a fellow, I should see my logged activities on the my activities page
- Fix deployment errors
- [#157182896] Connect the society page to the API
- [#157238451] Populate the category dropdown in the log activity form 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 andela-societies-frontend.