Hogyan hozhat létre portfólió webhelyet a React.js használatával

Miután a barátaim lemondták hétvégi terveinket, kerestem valamit, amivel megölhetném az időt. Végül egy portfólió-weboldal létrehozásának tervével végeztem, miután átnéztem a hosszú függőben lévő 'Wish-To-Do' listátdolgokat.

Sok órányi késõbbi technológiák és sablonok keresése során végül ezt a weboldalt hoztam létre a React.js segítségével, és Github oldalak segítségével. A weboldal kódját itt találja ( technikailag „ webalkalmazásnak ” hívják , de ehhez a cikkhez „weboldalként” fogok hivatkozni ... remélem, hogy rendben van).

Amit megtanul

  • A React.js néhány alapfogalma
  • Hogyan használjuk a HTML-webhelyről a create-react-app alkalmazást
  • A portfólió webhelyének telepítése a „Github-oldalak” használatával

Néhány fogalom, amelyet tudnod kell, mielőtt elkezdenénk ..

Megjegyzés - nyugodtan hagyja ki ezt a részt, ha már ismeri a React.js és a React Components alapfogalmait.

Ezek a pontok egy nagyon alapos elképzelést nyújtanak majd a React világról. Nagyon ajánlom, hogy tanulmányozzon többet a React-ről a dokumentációban, és a freeCodeCamp segítségével ismerkedjen meg.

Mi a React.js>

Egyelőre elég tudni, hogy a React.js a felhasználói könyvtár összetevőinek felépítéséhez használt JavaScript könyvtár. A Facebook mérnökei hozták létre, és manapság megingatja a JavaScript világot ..

Mi a React Component>

A React segítségével összetevőket osztályként vagy függvényként határozhat meg. Opcionális bemeneteket adhat meg a „ props ” nevű összetevőkhöz .

Az összetevők lehetővé teszik az UI független szakaszokra bontását, például fejlécre, láblécre és törzsre. Mindegyik komponens függetlenül fog működni, így minden egyes komponens önállóan beolvasható a ReactDOM-ba, az egész oldal befolyásolása nélkül.

Ez „életciklus-módszerekkel ” is jár, amelyek lehetővé teszik a végrehajtandó kóddarabok meghatározását az alkatrész állapota szerint, például a csatlakoztatás, a renderelés, a frissítés és a visszavonás.

A React komponensek saját kompromisszumokkal rendelkeznek. Például újrafelhasználhatunk egy összetevőt úgy, hogy exportáljuk más összetevőkbe, de néha zavaros, ha több összetevőt kezelünk, amikor egymásnak beszélünk és rendereket indítunk.

így nézne ki egy alkatrész!

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

Mi a GitHub Pages>

A GitHub Pages segítségével könnyedén telepítheti webhelyét a GitHub használatával ingyen és bármilyen infrastruktúra beállítása nélkül. Modulokat biztosítottak, hogy ne kelljen sok minden miatt aggódnia. Ha kitartasz a végéig, látni fogod, hogy a varázslat módjára működik!

Mielőtt továbblépne, győződjön meg róla, hogy ..

Döntse el, milyen tartalmat szeretne felvenni a webhelyére

Végezze el egyszer a legújabb önéletrajzát (ha még nincs, akkor most hozzon létre egyet, és halassza el a projektet a következő hétvégére?). Ez segít abban, hogy világos elképzelése legyen arról, hogy milyen információkat szeretne felvenni a portfólió weboldalára.

Keressen ihletet

Böngésszen az ingyenes portfólió-websablonok százai között az interneten, nézze meg, hogyan és mit használhat fel belőlük - vegyen elő egy tollat ​​és papírt, és vázoljon fel egy durva diagramot, hogy képet kapjon arról, hogyan fog kinézni a webhelye. Ezt a sablont fogom bemutatni.

Gyűjtsön néhány csodálatos képet magáról

Természetesen nem akar rosszul kinézni a saját portfólióján. Ezért ássa el fotóarchívumát, hogy megtalálja a webhelyéhez tökéletes fotókat.

Hangolódjon kedvenc lejátszási listájára

A legenda szerint a jó dolgok csak a jó zenével járnak ... és biztosan nem akar lemaradni nagyszerű dolgokról.

Ugorjunk be az épületrészbe

A következő szakaszokban leírom a portfólió alkalmazás felépítésének lépéseit, de nem kell ugyanazt a kódot követnie, amelyet használok. Koncentráljon a fogalmak elsajátítására, és mutasson némi kreativitást! A további olvasmányokat három szakaszra osztották.

  1. A React-alkalmazás beállítása
  2. A HTML oldal bontása React összetevőkre
  3. Az alkalmazás telepítése a Github oldalaira

A React-app beállítása

Mi lesz ezzel create-react-app- a modul által biztosított Facebook - amely segít létrehozni React.js alkalmazások könnyen és nem kell aggódni a fordításához szükséges eszközöket.

  • Menjen a konzolhoz, és futtassa npm install create-react-appa modul telepítését az npm-en keresztül ( npma használat előtt győződjön meg róla, hogy telepítette - további információkért kövesse ezt a linket).
  • Most futtassa, npm create-react-app ${project-name}amely lekéri a build szkripteket, és létrehoz egy fájlszerkezetet, amely így néz ki.
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

Hozzon létre egy componentsmappát a srckönyvtár alatt. Itt tároljuk az alkatrészeket a jövőben.

  • Másolja templatea publicmappába az összes képet, betűtípust, HTML- és CSS-fájlt a HTML- ről, amelyet használni kívánt .

Most a projektkönyvtárának így kell kinéznie.

  • Futtassa azt a npm installparancsot, amely a függő modulokat telepíti a node_modulekönyvtár alá .
  • Ha eddig megvan, akkor a npm startparancs futtatásával elindul a React alkalmazás a localhost. Lépjen ide, //localhost:3000és látnia kell a React-alkalmazás kezdőlapját.

A HTML oldal bontása React összetevőkre ..

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!