Here i write some stuff which can help beginner to follow the good practice/pattern for good coding skills and learning
Always define variable with authentic name like if we defining array for users,
Good Practice : users
Bad Practice : data, userdata, usersarray etc.
Always follow camelCase pattern when you define variables ,like if we have single user posts,
Good Practice : singleUserPosts
Bad Practice : data, userpost, userpostobj etc.
- When you are defining functions always define with authentic name also follow camelCase pattern,
Good Practice : getPosts, getUsers, updatePost, getApiFn, getSinglePostWithComments
Bad Practice : getdata, posts, getcomentposts etc.
- Create a util folder in you project and put all the functions which are you using through out the application apart from api , put only those functions which are generic and common, like e.g : concateName, getCurrentDate, createDateFormate etc,
- In react we use props normally for some work in parent child relations or in redux, so when you using props and relay on them e.g suppose i have a Header component which use prop to display the header heading of current screen , or any other example you take, so if Header component have a props name header, suppose i didn't pass the header prop from where we calling Header component it will show empty string, here is the solution in this pic you can see we have Header.defaultProps object which has a key header and value , so if i don't pass the header prop it will show default value,
- In react when we supply props to child component we can make a validation that props must be particular type like ,string, integer, array, object and etc, in this pic you can see i define a default props type for header props which must be string ,if i don't supply the string value it will show me warring ,