DefaultProps and PropTypes (React)
This artical is mostly related to beginner which are working on React for learning and want to learn as much as they can to get the best code practice concepts.
Default Props:
Here i will not spoon feed from basic but when we are calling a child component from any parent component we usually pass some props that later use in child component sometimes data having type array which are looping and here issue occur sometimes when data not transfer to child component but component render on screen same with some heading element etc, so for safety reason and don’t want to break code we can use default props which can be use as initial data. Example
PropTypes
propTypes are basically just strict validation of any data which you are receiving in props, suppose your child component is expecting props name data, headingTitle and brand you can mark this props as required props so if we don’t send this props from parent component to child the error will show on console that some(props name) are marked as required. Even you can define a type of props which you are expected. which will more validate and make system strong and reliable that no other then particular type will accept.
Some of the beginner do this mistake that they done follow the best practice in their initial path which lead them to, they consume more time to achieve the level of best Software Engineer and unfortunately I was one of them , that why I am contributing to give back least what I can do for the community.
YouTube channel : https://www.youtube.com/channel/UCkaoWtBz6ioLbNwRzIco5Yg