loading...
Cover image for Beginners Mistakes

Beginners Mistakes

zainbinfurqan profile image Zain Ahmed ・2 min read

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

Variables

  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.

Functions

  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,

propTypes:

  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

Posted on by:

zainbinfurqan profile

Zain Ahmed

@zainbinfurqan

Hye, I am Zain Ahmed Software Engineer by profession, i have complete my MCS degree from KU, and i work as MERN Stack developer, Expertise in React.js, Node.js, Vue.js, MongoDB, React Native ,

Discussion

pic
Editor guide