npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lyria-err

v1.1.1

Published

Módulo que te permite renderizar archivos de react usando express de manera sencilla

Downloads

36

Readme

lyria-err

NPM Version

Módulo que te permite renderizar archivos de React usando Express de manera sencilla.

Instalación

Para instalar lyria-err, utiliza:

npm install lyria-err

Uso

Antes que nada, asegúrate de tener instalado Express y haber creado un servidor HTTP (si ya tienes uno, puedes saltarte este paso):

npm install express

Crea un servidor HTTP usando Express:

const express = require("express");
const app = express();

app.listen(3000, () => {
  console.log("Servidor HTTP listo");
});

Ahora que tienes tu servidor web, llama al módulo lyria-err y configúralo:

const er = require("lyria-err");

er.configureReact(app, "./src/jsx");

// Como primer argumento, pasa el objeto app de tu servidor Express.
// Como segundo argumento, pasa la ruta de tus archivos JSX.

Una vez que has configurado el paquete lyria-err, puedes usarlo en cualquier ruta de tu servidor Express de la siguiente manera:

app.get("/", (req, res) => {
  res.renderReact("app"); // Nombre del archivo .jsx
});

También puedes pasarle props de la siguiente manera:

app.get("/", (req, res) => {
  res.renderReact("app", { Nombre: "Isman", Nick: "Isman" });
});

Archivo app.jsx

const React = require("react");

function App(prop) {
  return (
    <div>
      <h1>
        Hola {prop.Nombre} / {prop.Nick}
      </h1>
    </div>
  );
}

module.exports = App;

Archivo index.js completo

const express = require("express");
const app = express();
const er = require("lyria-err");

er.configureReact(app, "./src/jsx");

app.get("/", (req, res) => {
  res.renderReact("app", { Nombre: "Isman", Nick: "Isman" });
});

app.listen(3000, () => {
  console.log("Servidor HTTP listo");
});

¡Y así de simple puedes renderizar archivos de React usando Express como si fuera un renderizador de plantillas! Espero que les guste.

⚠️ ¡Atención!

Aunque puedes renderizar componentes React, ten en cuenta que no podrás utilizar algunas de sus características, como useState, useContext y useEffect. Aunque el código se ejecutará sin problemas, no podrás utilizar funciones que hagan uso de estos estados.

Para poder aprovechar estas características correctamente, te recomendamos utilizar server-side rendering. Si deseas aprender cómo hacerlo utilizando este paquete, únete a nuestro servidor de Discord: enlace al servidor de Discord.