HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Learn React Fast!</title>
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
</head>
<body>
<div id="flex">
<nav id="navbar">
<header>
<a class="nav-link" href="#Learn_React_Fast!"><img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9Ii0xMS41IC0xMC4yMzE3NCAyMyAyMC40NjM0OCI+CiAgPHRpdGxlPlJlYWN0IExvZ288L3RpdGxlPgogIDxjaXJjbGUgY3g9IjAiIGN5PSIwIiByPSIyLjA1IiBmaWxsPSIjNjFkYWZiIi8+CiAgPGcgc3Ryb2tlPSIjNjFkYWZiIiBzdHJva2Utd2lkdGg9IjEiIGZpbGw9Im5vbmUiPgogICAgPGVsbGlwc2Ugcng9IjExIiByeT0iNC4yIi8+CiAgICA8ZWxsaXBzZSByeD0iMTEiIHJ5PSI0LjIiIHRyYW5zZm9ybT0icm90YXRlKDYwKSIvPgogICAgPGVsbGlwc2Ugcng9IjExIiByeT0iNC4yIiB0cmFuc2Zvcm09InJvdGF0ZSgxMjApIi8+CiAgPC9nPgo8L3N2Zz4K" alt="" height="20"> Learn <code>React</code> Fast!</a><br>
<button class="nav-button"><a class="nav-link" href="#Before_we_start">Before we start</a></button>
<button class="nav-button"><a class="nav-link" href="#Introduction">Introduction</a></button>
<button class="nav-button"><a class="nav-link" href="#Basic">Basic</a></button>
<button class="nav-button"><a class="nav-link" href="#Some_things_to_have_in_mind">Some things to have in mind</a></button>
<button class="nav-button"><a class="nav-link" href="#Extra_information">Extra information</a></button>
</header>
</nav>
<main id="main-doc">
<section class="main-section" id="Learn_React_Fast!">
<header>
<h1>Learn <code>React</code> Fast!</h1>
<hr>
</header>
<p>
This technical page was made for a FreeCodeCamp project. If you like this please go to <a href="https://github.com/LMOlivera/Learn-React-fast" target="_blank">Github</a> and give me a star! Keep in mind this page is outdated and you should go to Github for more updated information.
</p>
</section>
<section class="main-section" id="Before_we_start">
<header>
<h1>Before we start</h1>
<hr>
</header>
<p>
I’m writing this because of two reasons:
<br>
<ol>
<li>The first is to ensure I know <code>React</code> so well that I can write a tutorial.</li>
<li>I consider most tutorials to be very slow and I like going fast and straight to action, so here you will see little text just to know what is going on. Because of this I will mention some features I won't cover because I consider them unnecesary.</li>
</ol>
</p>
<h2>Things you should know...</h2>
<p>
I assume you already know basic HTML and CSS, and have a good knowledge of Javascript. If you don't, I recommend you study and learn those first because you will not understand this fast tutorial.
</p>
<h2>Tools</h2>
<p>
<ul>
<li>codepen.io: Codepen allows you to write HTML, CSS and Javascript while seeing the results. Here is the link for a <code>React</code>.js template I made, just fork it and work on your own while reading this tutorial C:</li>
<li><code>React</code> CDN: You can use <code>React</code> through it's CDN.</li>
</ul>
</p>
</section>
<section class="main-section" id="Introduction">
<header>
<h1>Introduction</h1>
<hr>
</header>
<p>
<code>React</code>.js is an Open Source library developed by Facebook Developers, for building User Interfaces (UI). <code>React</code> makes user interfaces very easy to build by cutting each page into pieces. We call these pieces components.
</p>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/components.png" alt="Google components" class="center">
<p>
<code>React</code> is fairly easy to understand and at this moment has an excellent reputation and a great community. It supports ES6 and can perform client-side as well as server side rendering.
<br><br>
<b>Note</b>: Represents View in Model-View-Controller architectural pattern, that means you will need more tools in the future to cover the Model and Controller part.
</p>
<h2>Virtual DOM</h2>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/DOM%20and%20Virtual%20DOM.png" alt="DOM and Virtual DOM comparison" class="center">
<p>
Consider a page displaying a list containing 10 items and one is getting updated. DOM will rebuild the entire list making it work 10 times more than what is necessary.
<br><br>
Virtual DOM is an abstract, lightweight copy of DOM. It can be changed as and when we want and then can be saved to the real DOM. Whenever a change occurs, Virtual DOM efficiently rerenders the DOM. It is much faster than DOM. It has the same properties as a real DOM object.
</p>
<h2>JSX</h2>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/JSX%20example%201.png" alt="JSX example 1" class="center">
<br>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/JSX%20example%202.png" alt="JSX example 2" class="center">
<p>
<code>React</code> uses a syntax extension of JavaScript called JSX that allows you to write HTML directly within JavaScript (but JSX is NOT HTML). It is not necessary to use it but I recommend it as it makes your code more readable.
<ul>
<li>However, because JSX is not valid JavaScript, JSX code must be compiled into JavaScript. The transpiler Babel is a popular tool for this process.</li>
<li>Self-enclosing tags: An important way in which JSX differs from HTML is the idea of self-enclosing tags.</li>
</ul>
</p>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/Self-enclosing%20tags.png" alt="Self-enclosing tags" class="center">
<br>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/Self-enclosing%20tags%20output.png" alt="Self-enclosing tags output" class="center">
<p>
<b>Note</b>: You can use Javascript inside HTML (JSX) writing {code} (example in second picture). If you don't understand the code above please don't panic and come back in a few minutes.
</p>
</section>
<section class="main-section" id="Basic">
<header>
<h1>Basic</h1>
<hr>
</header>
<h2>Building Blocks of <code>React</code>JS</h2>
<p>
A typical <code>React</code>JS program constitutes:
</p>
<ul>
<li>Components.</li>
<li>Elements will not be covered here.</li>
<li>Props.</li>
<li>State.</li>
<li>Lifecycle.</li>
</ul>
<br>
<h3>
What is a <code>React</code> Component?
</h3>
<p>
Javascript function/class that represents a piece of a webpage. To build a page, we call these functions/classes in a certain order, put the result together, and show it to the user.
</p>
<b>Function component</b>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/Function%20component%201.png" alt="Function component" class="center">
<br>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/Function%20component%202.png" alt="Function component2" class="center">
<b>Class component</b>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/Class%20component.png" alt="Class component" class="center">
<br>
<p>
If we call the OurFirstComponent() function we’ll get back a bit of JSX. We can use something called ReactDOM.render(Component,locationForComponent) to put it on the page.
</p>
<b>Input example</b>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/ReactDOM.render%20example.png" alt="ReactDOM.render example" class="center">
<br>
<b>Output example</b>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/ReactDOM.render%20test%20result.png" alt="ReactDOM.render output example" class="center">
<br>
<b>When to use Function or Class component</b>
<p>
The main difference between Function or Class is that Classes have more features, like state, lifecycle, handling events, etc. You will learn about them soon.
</p>
<h3>Props</h3>
<p>
Inputs accepted by components.
</p>
<b>Working in a function</b>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/Function%20prop%20example.png" alt="Function prop example" class="center">
<br>
<b>Working in a class</b>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/Class%20prop%20example.png" alt="Class prop example" class="center">
<br>
<b>Result</b>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/Prop%20output%20example.png" alt="Prop output example" class="center">
<br>
<h3>State</h3>
<p>
State is similar to props, but it is private and fully controlled by the component. You have to add a constructor to the class in order to initialize the state.
</p>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/Component%20with%20state%20example.png" alt="Component with state example" class="center">
<br>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/Component%20with%20state%20output.png" alt="Component with state output example" class="center">
<br>
<h3>Lifecycle</h3>
<p>
You can see an excelent example of lifecycle in this pen (you should be able to understand it). There are two important methods in every <code>React</code> Component: componentDidMount() and componentWillUnmount().
<ul>
<li>componentDidMount(): When the component is rendered on the website this method is triggered. In the example it creates a setInterval for tick().</li>
<li>componentWillUnmount(): If for some reason the component is removed from the DOM, this method will be triggered. In the example clears the interval created by componentDidMount().</li>
</ul>
</p>
</section>
<section class="main-section" id="Some_things_to_have_in_mind">
<header>
<h1>Some things to have in mind</h1>
<hr>
</header>
<ul>
<li>It is consider a bad practice to change a Parents state from Child. Try to think how to manage Parents and Childs before programming, it will save you a lot of time.</li>
<ul><li>However, you can do this by binding a Parent function to the Child.</li></ul>
<br>
<li>Keep in mind you can style components in four ways:</li>
<br>
<b>You can give JSX a className (you can't use "class" because it is not HTML, it's JSX) to select it from CSS:</b>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/Styling%20components%20-%20CSS%20Stylesheet.png" alt="Styling by Stylesheet" class="center">
<br>
<b>Inline styling:</b>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/Styling%20components%20-%20Inline%20styling.png" alt="Styling by inline-styling" class="center">
<br>
<b>CSS Modules:</b>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/Styling%20components%20-%20CSS%20Modules.png" alt="Styling by CSS Modules" class="center">
<br>
<b>Styled components:</b>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/Styling%20components%20-%20Styled-components.png" alt="Styling by styled components" class="center">
<br>
</section>
<section class="main-section" id="Extra_information">
<header>
<h1>Extra information</h1>
<hr>
</header>
<p>
If you are here it means there are some concepts you probably don't know. I don't want you to waste time searching them, so here they are.
</p>
<ul>
<li><b>Elements</b>: An element describes what you want to see on the screen. Unlike browser DOM elements, <code>React</code> elements are plain objects, and are cheap to create. In the official documentation they talk more about them, but I consider it is a waste of time because you will be using Class Components most of the time.</li>
<br>
<img src="https://raw.githubusercontent.com/LMOlivera/Learn-React-fast/master/images/Element%20example.png" alt="Element" class="center">
<br>
<li><b>CDN (Content Delivery Network)</b>: Geographically distributed group of servers which work together to provide fast delivery of Internet content. A CDN allows for the quick transfer of assets needed for loading Internet content including HTML pages, javascript files, stylesheets, images, and videos. The popularity of CDN services continues to grow, and today the majority of web traffic is served through CDNs, including traffic from major sites like Facebook, Netflix, and Amazon. A properly configured CDN may also help protect websites against some common malicious attacks, such as Distributed Denial of Service (DDOS) attacks.</li>
</ul>
</section>
</main>
</div>
</body>
</html>
body{
font-family: Calibri;
background-color: #eee;
}
#navbar {
overflow: hidden;
background-color: #20232a;
position: fixed;
top: 0;
width: 50%;
text-align: center;
}
#navbar a {
color: #f2f2f2;
text-decoration: none;
}
#navbar a:hover {
background: #ddd;
color: black;
}
.nav-link{
margin: 0px 10px;
}
.nav-button{
border:0;
background-color:#20232a;
font-size: 16px;
}
.main-section{
padding-left: 0;
padding-top:50px;
}
#main-doc {
margin-top: 50px !important;
margin-left: 20vw !important;
text-align: justify;
}
.center {
display: block;
margin-left: auto;
margin-right: auto;
width:80%;
}
code{
color:#00B0FF;
text-shadow: 1px 1px #000000;
font-size: 24px;
}
@media(min-width: 650px){
#navbar{
overflow: hidden;
background-color: #20232a;
position: fixed;
left: 0;
width: 17vw;
height: 100%;
text-align: center;
}
#navbar a{
display: block;
color: #f2f2f2;
text-decoration: none;
font-size: 16px;
margin: 10px 0px;
}
.nav-link, #navbar a {
width: 15vw;
padding:10px;
}
.nav-button{
padding:0px;
margin:0;
}
#main-doc {
margin-top: -10px;
margin-left: 160px;
padding: 0px 20px;
}
}
@media(max-width: 850px){
.main-section{
padding-top:100px;
}
}
Also see: Tab Triggers