Join our Full-Stack Web Development Bootcamp and become a software engineer in 3 months

Why you should learn React!

Why learn React? And how can it make our lives easier as a frontend developer!

Home - Coding - Why you should learn React!

Let’sΒ assumeΒ thatΒ weΒ wereΒ taskedΒ byΒ ourΒ clientΒ toΒ createΒ 10Β pagesΒ ofΒ contentΒ forΒ theΒ company’sΒ website,Β allΒ withΒ theΒ sameΒ navigationΒ bar.

WeΒ proceedΒ toΒ designΒ theΒ navigationΒ barΒ andΒ placedΒ themΒ intoΒ 10Β differentΒ pages.

HereΒ areΒ someΒ examplesΒ ofΒ theΒ pages.

profile.html
example of an index page
index.html
‍

*PhoneΒ rings

OhΒ noes,Β theΒ clientΒ wantedΒ theΒ colorΒ ofΒ theΒ navigationΒ barΒ toΒ beΒ changedΒ toΒ #edfaff.

Welp,Β let’sΒ getΒ toΒ workΒ then.

WeΒ proceedΒ toΒ changeΒ theΒ colorΒ ofΒ theΒ navigationΒ barΒ andΒ replacedΒ theΒ navigationΒ barΒ inΒ theΒ pages.

profile.html
an example of index.html with changes made
index.html

‍*Client called again!

Whoops!!Β We’veΒ forgottenΒ toΒ applyΒ theΒ changeΒ toΒ aΒ fewΒ ofΒ theΒ pages.

AccidentsΒ likeΒ thisΒ happenΒ allΒ theΒ time,Β asΒ aΒ websiteΒ isΒ alwaysΒ comprisedΒ ofΒ manyΒ HTMLΒ pages. WeΒ areΒ notΒ perfectΒ humanΒ beings, makingΒ mistakesΒ hereΒ andΒ thereΒ isΒ perfectlyΒ normal!

Let’sΒ seeΒ howΒ weΒ canΒ solveΒ thisΒ problemΒ usingΒ React!

FirstΒ IΒ wouldΒ needΒ toΒ explainΒ whatΒ isΒ React.

ReactΒ isΒ aΒ front-endΒ libraryΒ thatΒ isΒ builtΒ onΒ JavaScript,Β inΒ essence,Β it’sΒ justΒ aΒ bunchΒ ofΒ functionsΒ andΒ codeΒ writtenΒ inΒ JavaScript, theΒ mainΒ purposeΒ ofΒ these codesΒ isΒ toΒ makeΒ developer’s lifeΒ easierΒ byΒ solvingΒ theΒ aboveΒ problemsΒ andΒ more.

InΒ React,Β aΒ developerΒ wouldΒ firstΒ defineΒ anΒ HTMLΒ templateΒ inΒ JavaScript,Β thatΒ templateΒ willΒ beΒ whatΒ weΒ callΒ aΒ component.

YouΒ canΒ thinkΒ ofΒ itΒ asΒ anΒ abbreviation/containerΒ forΒ aΒ bunchΒ ofΒ HTML,Β veryΒ coolΒ right?

TheΒ saidΒ componentΒ canΒ beΒ usedΒ anywhere,Β evenΒ inΒ otherΒ component.

Nesting of components
Component(s) can be nested inside another component

Β 

However,Β toΒ solveΒ theΒ aboveΒ problemΒ withΒ onlyΒ ReactΒ isΒ insufficient,Β soΒ weΒ haveΒ toΒ followΒ a practice calledΒ sourceΒ ofΒ truth.

SourceΒ ofΒ truth

LetΒ meΒ brieflyΒ explainΒ aΒ practiceΒ knownΒ asΒ sourceΒ ofΒ truth.

ForΒ everyΒ pageΒ ofΒ HTMLΒ weΒ have,Β weΒ willΒ haveΒ aΒ navigationΒ barΒ forΒ it.Β SinceΒ changingΒ theΒ navigationΒ barΒ ofΒ oneΒ ofΒ theΒ pagesΒ will notΒ changeΒ theΒ restΒ ofΒ theΒ pages, weΒ canΒ sayΒ thatΒ theyΒ areΒ fromΒ aΒ separateΒ sourceΒ ofΒ truth.Β ForΒ theΒ aboveΒ example,Β weΒ wouldΒ haveΒ 10Β differentΒ sourcesΒ ofΒ truthΒ forΒ theΒ navigationΒ bar.

OurΒ goalΒ isΒ toΒ getΒ everyΒ singleΒ HTMLΒ pageΒ toΒ useΒ aΒ navigationΒ barΒ templateΒ fromΒ onlyΒ oneΒ sourceΒ ofΒ truth.Β Hence,Β ifΒ thereΒ areΒ anyΒ changesΒ needed, weΒ onlyΒ needΒ to changeΒ fromΒ thatΒ sourceΒ ofΒ truthΒ whichΒ willΒ thenΒ beΒ appliedΒ ontoΒ allΒ theΒ pagesΒ simultaneously.

SOLUTION!

SoΒ nowΒ weΒ roughlyΒ knowΒ whatΒ ReactΒ isΒ andΒ alsoΒ understandΒ whatΒ is sourceΒ ofΒ truthΒ weΒ canΒ nowΒ implementΒ themΒ toΒ solveΒ ourΒ problem.

AΒ templateΒ ofΒ ourΒ navigationΒ barΒ canΒ beΒ definedΒ inΒ ourΒ component,Β theΒ componentΒ definedΒ isΒ nowΒ theΒ oneΒ sourceΒ ofΒ truthΒ forΒ ourΒ navigationΒ bar.

AlthoughΒ someΒ setupsΒ areΒ stillΒ requiredΒ forΒ React,Β butΒ afterΒ allΒ ofΒ that,Β youΒ canΒ useΒ theΒ definedΒ componentΒ likeΒ so.

Β 

TheΒ Β componentΒ aboveΒ willΒ recreateΒ allΒ theΒ HTMLΒ thatΒ areΒ definedΒ insideΒ ofΒ it.Β WeΒ canΒ thenΒ repeatΒ thisΒ onΒ theΒ otherΒ pagesΒ soΒ thatΒ theyΒ will allΒ useΒ theΒ sameΒ component,Β thusΒ achievingΒ oneΒ singleΒ sourceΒ ofΒ truthΒ forΒ theΒ navigationΒ bar!

Β 

Can’tΒ weΒ achieveΒ itΒ usingΒ JavaScript?

TechnicallyΒ speaking,Β youΒ can!

ByΒ usingΒ onlyΒ HTMLΒ orΒ combiningΒ itΒ withΒ JavaScript,Β itΒ isΒ entirelyΒ possibleΒ toΒ followΒ the practice ofΒ oneΒ sourceΒ ofΒ truth,Β butΒ it’sΒ notΒ a commonΒ practiceΒ toΒ doΒ itΒ andΒ itΒ hasΒ someΒ drawbacksΒ asΒ well.Β 

SoΒ whyΒ doΒ weΒ preferΒ ReactΒ overΒ JavaScript?

WriteΒ less,Β achieveΒ more.

DecreaseΒ developmentΒ time,Β increaseΒ productivity.

ReactΒ offersΒ reusableΒ components,Β whichΒ meansΒ thatΒ theΒ HTMLΒ thatΒ weΒ writeΒ inΒ ReactΒ areΒ allΒ potentiallyΒ reusable,Β thusΒ reducingΒ theΒ amountΒ ofΒ code neededΒ significantly.

ItΒ feelsΒ likeΒ usingΒ aΒ photostatΒ machineΒ versusΒ handwritingΒ documents.

MoreΒ organizedΒ code,Β fasterΒ debuggingΒ time.

ReactΒ alsoΒ allowsΒ easierΒ logicΒ implementation.Β ForΒ example,Β ifΒ weΒ haveΒ anΒ emailΒ inputΒ fieldΒ thatΒ needsΒ toΒ beΒ checkedΒ forΒ aΒ validΒ email,Β itsΒ logic canΒ beΒ easilyΒ beΒ containedΒ inΒ oneΒ component,Β andΒ thenΒ beΒ reusedΒ wheneverΒ weΒ needΒ it.

LogicalΒ bugsΒ canΒ alsoΒ beΒ trackedΒ downΒ fairlyΒ easily.Β IfΒ aΒ componentΒ isn’tΒ behavingΒ asΒ itΒ should,Β sinceΒ allΒ logicsΒ forΒ aΒ componentΒ isΒ contained withinΒ oneΒ singleΒ file,Β theΒ bugΒ canΒ beΒ foundΒ withinΒ aΒ shortΒ amountΒ ofΒ time.

SameΒ structure,Β differentΒ platform.

AfterΒ learningΒ howΒ toΒ workΒ withΒ React,Β weΒ canΒ easilyΒ startΒ workingΒ withΒ ReactΒ Native!

WithΒ ReactΒ Native,Β weΒ canΒ nowΒ developΒ mobileΒ appsΒ forΒ bothΒ AndroidΒ andΒ iOSΒ platforms.

WriteΒ onlyΒ oneΒ ReactΒ NativeΒ app,Β andΒ itΒ canΒ thenΒ beΒ ‘translated’Β intoΒ bothΒ AndroidΒ andΒ iOSΒ apps,Β soΒ youΒ don’tΒ haveΒ toΒ writeΒ both!

ReactΒ NativeΒ isΒ structurallyΒ similarΒ toΒ React.Β SoΒ youΒ wouldΒ onlyΒ haveΒ toΒ learnΒ theΒ nuancesΒ ofΒ ReactΒ Native!

Conclusion

ReactΒ isΒ aΒ reallyΒ powerfulΒ toolΒ thatΒ aΒ frontendΒ developerΒ canΒ useΒ toΒ increaseΒ productivityΒ andΒ reduceΒ developmentΒ time.Β ThisΒ isΒ especially importantΒ whenΒ weΒ areΒ workingΒ withΒ bigΒ projectsΒ whereΒ weΒ haveΒ toΒ workΒ withΒ aΒ lotΒ ofΒ pages.

TheΒ demandΒ forΒ frontendΒ developersΒ whoΒ knowsΒ howΒ toΒ workΒ withΒ ReactΒ isΒ onΒ theΒ riseΒ rightΒ now,Β soΒ learningΒ ReactΒ willΒ alsoΒ increaseΒ the chanceΒ ofΒ gettingΒ aΒ jobΒ asΒ well!

Website | + posts

Share:

Facebook
LinkedIn
Twitter
WhatsApp
Email
Also on The NEXT Blog

Ready to learn?

Great for you if you want to learn specific stuff but not necessarily to get a job.

Free Resources

Digital Marketing Course Preview

Skill Courses | Remote

2-in-1 Paid Advertising: Google, Youtube, Facebook Instagram Ads

Mini Marketing Courses Pre-Launch Offer

Great for you if you want to give coding a try. Also great if you are learning to code for specific stuff but not necessarily to get a job.

Topic Specific Courses

3-Day HTML, CSS & Bootstrap Online Course | Level 0

Code Your Algo Trading Bot with Python

Free Resources

Programming 101