Kuidas luua oma portfelli veebisait React.js abil

Pärast seda, kui mu sõbrad meie nädalavahetuse plaanid tühistasid, otsisin midagi, mis aega tapaks. Lõpuks jõudsin plaanini luua portfelliveeb pärast seda, kui olen läbi vaadanud oma pika ooteloendi soovidestasju.

Mitu tundi hiljem tehnoloogiaid ja malle otsides lõin lõpuks selle veebisaidi React.js-i abil ja Githubi lehtedel. Veebisaidi koodi leiate siit (seda nimetatakse tehniliselt veebirakenduseks , kuid selle artikli puhul viitan sellele kui "veebisaidile" ... loodan, et see on ok).

Mida õpid

  • React.js mõned põhimõisted
  • Kuidas HTML-veebisaidilt luua-reageerida-rakendust kasutada
  • Kuidas oma portfelli veebisaiti Githubi lehtede abil juurutada

Mõned mõisted, mida peate enne alustamist teadma.

Märkus - jätke see osa julgelt vahele, kui olete React.js ja React Components põhimõistetega juba tuttav.

Need punktid pakuvad väga lihtsat ideed Reacti maailmast. Soovitan teil tungivalt Reactist lähemalt uurida dokumentatsioonist ja saada freeCodeCampi abil käed külge.

Mis on React.js>

Praegu piisab teadmisest, et React.js on JavaScripti teek, mida kasutatakse kasutajaliidese komponentide loomiseks. Selle lõid Facebooki insenerid ja tänapäeval raputab see JavaScripti maailma.

Mis on reageeriv komponent>

Reageeri abil saate komponente määratleda klassi või funktsioonina. Võite pakkuda valikulisi sisendeid komponentidele, mida nimetatakse rekvisiitideks .

Komponendid võimaldavad teil kasutajaliidese jagada iseseisvateks osadeks, näiteks päiseks, jaluseks ja kehaks. Iga komponent töötab iseseisvalt, nii et iga üksiku komponendi saab eraldada ReactDOM-i iseseisvalt, ilma et see mõjutaks tervet lehte.

Kaasas on ka „elutsüklimeetodid ”, mis võimaldavad teil määratleda kooditükid, mida soovite täita vastavalt komponendi olekule, näiteks paigaldamine, renderdamine, värskendamine ja eemaldamine.

Reaktiivkomponentidel on omad kompromissid. Näiteks võime komponenti taaskasutada, eksportides selle teistesse komponentidesse, kuid mõnikord tekitab segadust mitme komponendi käsitlemine ja üksteise jaoks renderduste käivitamine.

nii näeb komponent välja!

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

Mis on GitHubi lehed>

GitHubi lehtede abil saate oma saidi hõlpsalt GitHubi kasutades tasuta juurutada ja ilma infrastruktuuri seadistamata. Nad on pakkunud mooduleid, et te ei peaks paljude asjade pärast muretsema. Kui jääte lõpuni ringi, näete, et see töötab nagu VÕLU!

Enne kui jätkate, veenduge, et ..

Otsustage, millist sisu soovite oma veebisaidile panna

Vaadake üks kord läbi oma viimane CV (kui teil seda pole, siis looge see nüüd ja lükake see projekt järgmise nädalavahetuseni?). See aitab teil saada selge ettekujutuse selle kohta, millist teavet soovite oma portfelli veebisaidile panna.

Leidke inspiratsiooni

Sirvige veebis sadu tasuta portfelli veebisaidi malle, vaadake, kuidas ja mida saate neist kasutada - võtke pastakas ja paber välja ning visandage ligikaudne skeem, et saada aimu, milline teie veebisait välja näeb. Kasutan demonstreerimiseks seda malli.

Koguge endast hämmastavaid pilte

Muidugi ei taha sa oma portfelli veebisaidil halb välja näha. Nii et uurige oma fotode arhiive, et leida oma veebisaidile sobivad fotod.

Häälestage oma lemmik esitusloendisse

Legend räägib, et head asjad tulevad ainult hea muusikaga ... ja kindlasti ei taha te suurtest asjadest ilma jääda.

Hüppame hooneosasse

Järgmistes jaotistes kirjeldan portfellirakenduse loomise samme, kuid te ei pea järgima sama koodi, mida kasutan. Keskenduge mõistete õppimisele ja näidake üles loovust! Edasine lugemine on jagatud kolme ossa.

  1. Rakenduse React seadistamine
  2. HTML-lehe jaotamine React komponentideks
  3. Rakenduse juurutamine Githubi lehtedele

Rakenduse React seadistamine

Kasutame create-react-app- Facebooki pakutavat moodulit -, mis aitab meil React.js-i rakendusi hõlpsalt ja ehitustööriistade pärast muretsemata luua.

  • Minge konsooli ja käivitage npm install create-react-appselle mooduli installimine npm kaudu (veenduge, et olete selle npmenne kasutamist installinud - lisateabe saamiseks järgige seda linki).
  • Nüüd käivitage see, npm create-react-app ${project-name}mis toob üles ehituskriptid ja loob failistruktuuri, mis näeb välja selline.
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

Looge componentskataloogi alla kaust src. Siin hoiame oma komponente tulevikus.

  • Kopeerige kausta kõik pildid, fondid, HTML- ja CSS-failid HTML-ist, millega templateotsustasite töötada public.

Nüüd peaks teie projektikataloog välja nägema selline.

  • Käivitage npm installkäsk, mis installib sõltuvad moodulid node_modulekataloogi.
  • Kui teil on see siiani olemas, käivitatakse npm startkäsu käivitamisel rakendus React localhost. Minge aadressile //localhost:3000ja peaksite nägema rakenduse Reactan avalehte.

HTML-lehe jaotamine React komponentideks.

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: tipptasemel mallide pakkumise eest, mis olid minu portfelli veebisaidile tohutuks inspiratsiooniks. ?
  • Daniel Lo Nigro & kogukond: luua HTML JSX tõlkija, mis osutus mugav samas ümberehituseks HTML plokid JSX koodi. ?
  • Mu kallimad sõbrad: kes aitasid mul vigu parandada.
  • TEIE: ringi liikumise eest loodan, et teil oli produktiivne aeg. Jätkake hämmastavate asjade uurimist ja ehitamist!