Kako izraditi web stranicu portfelja pomoću React.js-a

Nakon što su moji prijatelji otkazali planove za vikend, tražio sam nešto da ubijem vrijeme. Napokon sam završio s planom za stvaranje web stranice s portfeljem nakon što sam prošao svoj dugački popis "Želim učiniti"stvari.

Mnogo sati kasnije tražeći tehnologije i predloške, na kraju sam stvorio ovo web mjesto koristeći React.js i rasporedio ga na Github stranicama. Kôd za web mjesto možete pronaći ovdje ( tehnički se zove ' web-aplikacija ', ali u ovom ću ga članku nazivati 'web mjesto' ... Nadam se da je to u redu).

Što ćete naučiti

  • Neki osnovni koncepti React.js
  • Kako koristiti aplikaciju create-response-s HTML web stranice
  • Kako rasporediti web mjesto portfelja pomoću 'Github stranica'

Neke pojmove koje morate znati prije nego što započnemo ..

Napomena - slobodno preskočite ovaj dio ako ste već upoznati s osnovnim pojmovima React.js i React Components.

T hese točke osigurat će vrlo Osnovna ideja reagirati svijet. Toplo vam preporučujem da proučite više o Reactu iz dokumentacije i upoznate se uz pomoć freeCodeCampa.

Što je React.js>

Za sada je dovoljno znati da je React.js JavaScript knjižnica koja se koristi za izgradnju komponenata korisničkog sučelja. Stvorili su ga inženjeri Facebooka i danas potresa JavaScript svijet ..

Što je React komponenta>

React vam omogućuje definiranje komponenata kao klase ili funkcije. Neobavezne ulaze možete dati komponentama koje se nazivaju ' rekviziti '.

Komponente omogućuju dijeljenje korisničkog sučelja na neovisne odjeljke poput zaglavlja, podnožja i tijela. Svaka komponenta će raditi neovisno, tako da se svaka pojedinačna komponenta može prikazati neovisno u ReactDOM bez utjecaja na cijelu stranicu.

Također dolazi s 'metodama životnog ciklusa ' koje vam omogućuju da definirate dijelove koda koje želite izvršiti u skladu sa stanjem komponente, poput montiranja, prikazivanja, ažuriranja i poništavanja.

React komponente dolaze s vlastitim kompromisima. Na primjer, možemo ponovno upotrijebiti komponentu tako što ćemo je izvesti u druge komponente, ali ponekad postaje zbunjujuće rukovanje više komponenata koje međusobno razgovaraju i pokreću rendere.

ovako bi komponenta izgledala!

import React, { Component } from 'react' export default class Component-name extends Component { render() { return ( {these code will be rendered into the DOM} ) } }

Što su GitHub stranice>

S GitHub stranicama možete jednostavno instalirati svoju web lokaciju koristeći GitHub besplatno i bez potrebe za postavljanjem bilo kakve infrastrukture. Osigurali su module tako da se ne morate brinuti o mnogim stvarima. Ako se držite do kraja, vidjet ćete da to djeluje poput MAGIJE!

Prije nego što nastavite, svakako ...

Odlučite koji sadržaj želite postaviti na svoju web stranicu

Prođite jednom kroz svoj najnoviji životopis (ako ga nemate, napravite ga sada i odgodite ovaj projekt za sljedeći vikend?). Pomoći će vam da imate jasnu predodžbu o tome kakve informacije želite staviti na web mjesto svog portfelja.

Pronađite inspiraciju

Pregledajte stotine besplatnih predložaka web stranica s portfeljem na internetu, pogledajte kako i što od njih možete koristiti - izvadite olovku i papir i skicirajte okvirni dijagram kako biste dobili ideju kako će vaše web mjesto izgledati. Koristit ću ovaj predložak za demonstraciju.

Skupite neke svoje nevjerojatne slike

Naravno da ne želite izgledati loše na vlastitom web mjestu portfelja. Stoga kopajte po svojoj arhivi fotografija da biste pronašli savršene fotografije za svoju web stranicu.

Ugodite svoj omiljeni popis za reprodukciju

Legenda kaže da dobre stvari dolaze samo s dobrom glazbom ... i zasigurno ne želite propustiti neke sjajne stvari.

Uskočimo u dio zgrade

U sljedećim odjeljcima opisat ću korake za izgradnju aplikacije portfelja, ali ne morate slijediti isti kod koji koristim. Usredotočite se na učenje koncepata i pokažite malo kreativnosti! Daljnja literatura podijeljena je u tri odjeljka.

  1. Postavljanje aplikacije React
  2. Razbijanje HTML stranice na komponente React
  3. Implementacija vaše aplikacije na Github stranice

Postavljanje React-aplikacije

Koristit ćemo create-react-app- modul koji pruža Facebook - koji nam pomaže u stvaranju React.js aplikacija s lakoćom i bez brige o alatima za izgradnju.

  • Idite na konzolu i pokrenite npm install create-react-appinstaliranje ovog modula putem npm (provjerite jeste li instalirali npmprije upotrebe - slijedite ovu vezu za više informacija).
  • Sada pokrenite npm create-react-app ${project-name}koji će dohvatiti skripte za izgradnju i stvoriti strukturu datoteka koja će izgledati ovako.
my-portfolio-app ├── README.md (description of the project for GitHUb) ├── node_modules (stores all dependent modules for the project) ├── package.json (stores all meta information of the prokect like dependencies,version,revisions etc.) ├── .gitignore (files declared here will be ignored while uploading to GitHub like node_modules ├── public (here you will store all images,JS,CSS files) │ ├── favicon.ico │ ├── index.html │ └── manifest.json └── src (our main code for app lies here) ├── {create component folder here} ├── App.css ├── App.js ├── App.test.js ├── index.css ├── index.js ├── logo.svg └── serviceWorker.js

Stvorite componentsmapu ispod srcdirektorija. Tu ćemo pohraniti naše komponente u budućnosti.

  • Kopirajte sve slike, fontove, HTML i CSS datoteke iz HTML-a s kojim templateste odlučili raditi u publicmapu.

Sada bi vaš direktorij projekata trebao izgledati ovako.

  • Pokrenite npm installnaredbu koja će instalirati ovisne module u node_moduledirektorij.
  • Ako ste to dosad već imali, pokretanje npm startnaredbe pokrenut će aplikaciju React na localhost. Idite na //localhost:3000i trebali biste moći vidjeti početnu stranicu React-aplikacije.

Razbijanje HTML stranice na komponente React ..

Remember the component folder which we created under src directory in the previous step, now we will break down the HTML template page into components and combine these components to make our React-app.

  • First, you need to identify which components you can create from the monolithic HTML file — like header, footer and contact me. You need to be a little creative here!!
  • Look for tags like section/div which aren’t nested into some other section/div. These should contain code about that particular section of the page which is independent of other sections. Try looking into my GitHub Repo to get a better idea about this one.

    Hint: Use the ‘inspect element’ tool to play around with the code and take notice of the effect of changes within the browser.

  • These pieces of HTML code will be used in the render() method of the component. The render() method will return this code whenever a component gets rendered into the ReactDOM. Take a look at the code blocks given below for reference.

    
  • Hi!

    I'm Jackson

    100% html5 bootstrap templates Made by colorlib.com

    Download CV

  • I am

    a Designer

    100% html5 bootstrap templates Made by colorlib.com

    View Portfolio

import React, { Component } from 'react' export default class Home extends Component { render() { return ( 
    
  • Hi!

    I'm Jackson

    100% html5 bootstrap templates Made by colorlib.com

    Download CV

  • I am

    a Designer

    100% html5 bootstrap templates Made by colorlib.com

    View Portfolio

) } }

Hint: If things are getting confusing on the react side — try focusing on the concept of ‘how to identify wanna be components from the HTML codebase’. After getting comfortable with React, implementation will be a piece of cake.

Did you notice that there are some changes in the HTML code? class became className. These changes are required because React doesn’t support HTML ? — they have come up with their own HTML-like JS syntax which is called JSX . So, we need to change some parts of the HTML code to make it JSX.

I bumped into this HTML to JSX converter during this project, which converts HTML code into JSX for you ?. I highly recommend using this rather than changing your code manually.

After some time, you should come up with some different components. Now the EndGame is near!! Combine these different components under one App.js component (YES!! You can render one component from another component!) and your portfolio app will be ready.

import React, { Component } from 'react'; import './App.css'; import Sidebar from './components/sidebar' import Introduction from './components/introduction' import About from './components/about' import Projects from './components/projects' import Blog from './components/blog' import Timeline from './components/timeline' class App extends Component { render() { return ( ); } } export default App;

Notice in the above code that we need to first import the components in order to use them in the render() section. And we can use the components just by adding or just tag in the render method.

  • Run npm start from your terminal and you should be able to see the changes reflected in the website. You don’t need to run this command again if you have made more changes in the code, it will be reflected automatically when you save those changes. You can do some lightning fast development thanks to the hot reload feature.
  • Play around with the HTML and CSS to change the content according to your resume and make your portfolio even cooler by changing the content, trying out different fonts, changing the colours and adding photos of your choice.

Deploy React-app to Github pages

Okay, so you survived until this point… take a moment to appreciate your hard work. But you still need to complete your deployment so that you can share your cool work with your friends who ditched those weekend plans.

  • First, you need to install the npm library of Github pages. To install, run this command npm install gh-pages on your terminal.

Now, you need to make the following changes in your manifest.json file:

  • Add the homepage field — value will be in the following format — //{github_id}.github.io/{github_repo}
  • Add predeploy and deploy fields under scripts

Now your manifest.json should look like this:

{ "name": "portfolio-app", "version": "0.1.0", "private": true, "homepage": "//Dhruv34788.github.io/me", "dependencies": { "gh-pages": "^2.0.1", "react": "^16.8.3", "react-dom": "^16.8.3", "react-scripts": "2.1.5", "yarn": "^1.13.0"}, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "predeploy": "yarn run build", "deploy": "gh-pages -d build", "test": "react-scripts test", "eject": "react-scripts eject"}, "eslintConfig": { "extends": "react-app"}, "browserslist": [ ">0.2%", "not dead", "not ie <= 11", "not op_mini all" ] }

Now go to the terminal, run npm run deploy and wait for the magic!! Your app will be deployed after the deployment scripts execute successfully. Verify whether your app has deployed or not by visiting the link you provided in the homepage field.

Caution: Please be careful when deploying anything onto the web. Perform safety checks like removing internal links, passwords, or anything that you don’t want to be there in the hands of smart people out there.

If you are going to make changes often...

Note —  You need to perform the deployment stage every time you change something and if you are making changes in the codebase - guess what whose going to get bored soon !!  ( No worries I got your back :P)

You can automate the deployment process using Travis-CI (automation tool), so that if you commit anything into master branch – the deployment steps will be triggered and new site will be automatically available. Follow this article for that.

//www.freecodecamp.org/news/learn-how-to-automate-deployment-on-github-pages-with-travis-ci/

Homework for you ..

Congratulations! You have finally created and deployed your portfolio app. If you are interested, then you can add these features to your website

  • Blog feature: create your own blog using Node.js and a NoSQL database like MongoDB and merge it into this portfolio website.
  • Gallery: add a section to the page where you can show the screenplay of the recent photos from your social media websites.
  • Twitter Feed: add a section showing recent tweets by you.
  • Random Quote: add a section showing some random motivational quotes.

If you implement any of these features, share your work with me. I would be more than happy to help ? ( if I can ?)

Wrapping up ..

I would like to take a moment to acknowledge the work of the people who gave me the inspiration and knowledge to complete this article.

  • Quincy Larson, Sahat Yalkabov & community: For creating freeCodeCamp — the platform where you can learn and gain knowledge about almost everything related to web technologies; using hands-on tutorials and all without paying fees. ?
  • Colorlib: for providing state of the art templates which were a huge inspiration for my portfolio website. ?
  • Daniel Lo Nigro & community: for creating HTML to JSX Compiler, which turned out to be handy while converting HTML blocks into JSX code. ?
  • My dearest friends: who helped me in correcting my mistakes.
  • YOU: for sticking around, I hope you had a productive time. Keep exploring and building amazing things!