01 reactjs

01.- Curso de Reactjs ⚛️ [Que es y cómo instalarlo]

01%2Breactjs

¿Que es reactjs?

¿Un lenguaje de programación?: No
¿Un framework?: No
Reactjs es una librería hecha para poder programar nuestra aplicaciones de forma fácil sencilla y basada en componentes y cada componente es independiente a los demá, lo que me recuerda a iframe. Si llegaron a usar Iframe, un iframe era una forma de meter una pagina web dentro de otra y esos iframes eran independientes a los demás.

# Instalamos npm
sudo apt-get install npm
# Con npm instalamos react
sudo npm install -g create-react-app
# nos movemos a la carpeta donde se creara el proyecto
cd /var/www/html
# Creamos el proyecto
create-react-app react-hola-mundo
# Entramos en la carpeta del proyecto
cd react-hola-mundo
Nota: los nombres de los proyectos en react no pueden llevar “MAYUSCULAS” ni espacio, si quieren separar las palabras se recomienda user guión medio “-“.

Ya que tenemos instalado reactjs vamos a prender en primer lugar a comprender la estructura de archivos de esta libreria y ademas crearemos nuestra primer app en base a la estructura de ejemplo que nos da reactjs. Para esto vamos atrabajar el siguiente código:

public/index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <!--
      manifest.json provides metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    -->
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
    <!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <title>React App</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <div id="MiElemento"></div>
    
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
  </body>
</html>

src/MiApp/MiApp.css

.MiApp {
  text-align: center;
}

.MiApp-logo {
  animation: MiApp-logo-spin infinite 20s linear;
  height: 40vmin;
  pointer-events: none;
}

.MiApp-header {
  background-color: #fff;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: calc(10px + 2vmin);
  color: black;
}

.MiApp-link {
  color: blue;
}

@keyframes MiApp-logo-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

src/MiApp/MiApp.js

import React from 'react';
import logo from './../logo.svg';
import './MiApp.css';

function MiApp() {
  return (
    <div className="MiApp">
      <header className="MiApp-header">
        <img src={logo} className="MiApp-logo" alt="logo" />
        <p>
          Edit <code>src/MiApp.js</code> and save to reload.
        </p>
        <a
          className="MiApp-link"
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        >
          Learn React
        </a>
      </header>
    </div>
  );
}

export default MiApp;

src/index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import MiApp from './MiApp/MiApp';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(<App />, document.getElementById('root'));
ReactDOM.render(<MiApp />, document.getElementById('MiElemento'));

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *