It was easy to set up as React is a JavaScript(JS) framework and it comes with a lot of pre-built features but I did run into some challenges when making calls to other parts of the project for example calling the nav bar component from the homepage component. I realised quickly I didn’t understand how React components work and I was unfamiliar of the syntax. For example, in JS it was fairly straightforward designing functions and calling those functions inside other functions. React implements the idea of a ‘parent’ component and every other component being a ‘child’ of the parent. Here, things got a little bit more complicated with the introduction of Stateless Functional Components, Constructors, State and Props - where each of these belong in the code and their limitations. Some key learnings which I found useful were:
-
Constructor is owned by the ‘parent’ component where you define the state and state is then passed as props to the child component. The child component cannot make changes to the Constructor - only the parent can.
-
State (referred to as this.state) is created inside the component and its scope is limited to inside the component itself.
-
Prop (referred to as this.props or props) is external to the component and is controlled by whatever renders the component.
comments powered by