Categories
Utveckling

React JS Handledning för nybörjare

Förra helgen försökte jag hitta repet för ReactJS SPA (Single Page Application) för att ta reda på den bästa mappstrukturen som kan användas för React js-projekt. Jag kunde inte hitta något på mappstrukturen, men kunde hitta två start-/boilerplate-repos. Jag bestämde mig för att lära mig mer om de två start-/boilerplate-reposen för att själv kunna göra ett exempel på mappstruktur som ska användas i ReactJS-projekt.

1) create-react-app –

Create-react-appen är utvecklad/konfigurerad av Facebook som en del av Facebook inkubator. Det här verktyget hjälper dig att skapa React-appar utan behov av någon bygg konfiguration.

2) generator-react-webpack –

“generator-react-webpack” är en yomen-generator för ReactJS-applikationer och kan användas för att snabbt sätta upp ett projekt tillsammans med karmatest löparen och Webpack-modulsystemet.

 

Jag har installerat create-react-appen i mitt lokala system – den har en mycket enkel installation procedur och kräver ingen konfiguration. Jag föreslår att du går igenom filen “README.md” för att veta mer om installationsproceduren för create-react-app.

 

Jag har skapat en annan repo att implementera sma-react-boilerplate. Du bör se till att repet är klonat för att se de relaterade filerna som visas i bilden nedan. Jag har inte arbetat med att utveckla en CSS för att göra sidan mer attraktiv eftersom den här handledningen bara är en grundläggande demonstration av verktyget.

React js tutorial for beginners

 

Den “public”-mappen innehåller index.html- och .favicon-filer, och de bör inte röras med. Mappen som kräver vår största uppmärksamhet är “src” – mer känd som “en utvecklares lekplats.” Den här mappen innehåller en index.js-fil, som är ett av kärn elementen i programmet. Den här filen används för att skriva applikationens router egenskaper. Rot(“/”)-routern här pekar mot Home-komponenter så att användaren kan se “Hemsidan” när han försöker ringa.

React js tutorial - react js app tutorial

 

Inuti mappen “src” har jag skapat separata filer för varje sida som Home.js, About.js, Contact.js, etc. Varje fil innehåller en “components”-mapp. Den här mappen används för att behålla komponenterna på varje sida. Du kan hänvisa till Contact.js-filen och kontakt mappen för mer klarhet. Varje mapp kan ha olika komponenter och kan sparas i olika filer.

React js tutorial - contact-js-react-app

Slutligen har vi ytterligare tre mappar – “Common”, “layout” och “Forms” – i mappen “components”. Mappen “Common” används för generiska komponenter medan mappen “Layout” används för att spara filer relaterade till sidhuvudet och sidfoten. Mappen “Form” kan nås för element som Textbox, Textarea, etc. Dessa mappar kan betraktas som vanliga komponenter beroende på scenariot.

 

Jag hoppas att du har en allmän idé om att utveckla en exempel applikation och den mappstruktur som är kopplad till den. Dessa enkla koncept kan användas för att utveckla små och stora applikationer, men kom ihåg att de tunga applikationerna kräver en mer modulär mappstruktur. Du kan kontakta mig på https://twitter.com/shemeermali för alla frågor du kan ha om ämnet.

 

Glad reaktiv kodning

 

 

 

 

Categories
DEVELOPMENT

React JS Tutorial for Beginners

Last weekend, I was trying to find the boilerplate repo for ReactJS SPA (Single Page Application) to figure out the best folder structure that can be adopted for React js projects. I could not find anything on the folder structure, but was able to find two starter/boilerplate repos. I decided to learn more about the two starter/boilerplate repos in order to make a sample folder structure by myself, to be used in ReactJS projects.

1) create-react-app –
The create-react-app is developed/configured by Facebook as part of the Facebook incubator.  This tool will help you to create React apps without the need for any build configuration.

2) generator-react-webpack –
The “generator-react-webpack” is a yomen generator for ReactJS applications and can be used to quickly set up a project along with the karma test runner and the Webpack module system.

 

I have installed  the create-react-app in my local system –  it has a very simple installation procedure and doesn’t require any configuration. I suggest going through the “README.md” file to know more about the installation procedure to create-react-app.

 

I have created another repo to implement sma-react-boilerplate. You should make sure that the repo is cloned to see the related files as shown in the image below. I have not worked on developing a CSS to make the page more attractive as this tutorial is just a basic demonstration of the tool.

 

React js tutorial for beginners



The “public” folder contains index.html and .favicon files, and they should not be messed with. The folder that requires our utmost attention is “src” – more commonly known as ‘a developer’s playground.’ This folder contains an index.js file, which is one of the core elements of the application. This file is used to write the router characteristics of the application. The root(“/”) router here is pointed to Home components for the user to see the ‘Home Page’ when attempting a call.

 

React js tutorial - react js app tutorial



Inside the “src” folder, I have created separate files for each page like Home.js, About.js, Contact.js, etc. Each file contains a “components” folder. This folder is used to keep the components of each page. You can refer the Contact.js file and the Contact folder for more clarity. Each folder may have different components and can be saved in different files.



React js tutorial - contact-js-react-app



Finally, we have three more folders –  “Common”, “layout” and “Forms” – within the “components” folder. The “Common” folder is used for generic components while the “Layout” folder is used to save files related to the Header and the Footer. The “Form” folder can be accessed for elements like Textbox, Textarea, etc. These folders can be considered as common components depending on the scenario.

 

I hope that you have got a general idea about developing a sample application and the folder structure associated with it. These simple concepts can be used in developing small and large scale applications, but keep in mind that the heavy applications require a more modular folder structure. You can reach out to me at https://twitter.com/shemeermali for any queries that you may have on the subject.

 

Happy Reactive Coding