DEV Community

Cover image for Beginners Mistakes
Zain Ahmed
Zain Ahmed

Posted on

Beginners Mistakes

Here i write some stuff which can help beginner to follow the good practice/pattern for good coding skills and learning


  1. Always define variable with authentic name like if we defining array for users,
    Good Practice : users
    Bad Practice : data, userdata, usersarray etc.

  2. Always follow camelCase pattern when you define variables ,like if we have single user posts,
    Good Practice : singleUserPosts
    Bad Practice : data, userpost, userpostobj etc.


  1. 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.

  1. 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,

Default props:

  1. 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 Alt Text 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,


  1. 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, Alt Text 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 , Alt Text

Top comments (0)