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

@mrdotb/live-react

v0.2.0-rc-0

Published

[![Hex.pm](https://img.shields.io/hexpm/v/live_react.svg)](https://hex.pm/packages/live_react) [![Hexdocs.pm](https://img.shields.io/badge/docs-hexdocs.pm-purple)](https://hexdocs.pm/live_react) [![GitHub](https://img.shields.io/github/stars/mrdotb/live_r

Downloads

946

Readme

Hex.pm Hexdocs.pm GitHub

LiveReact

React inside Phoenix LiveView.

logo

Features

  • End-To-End Reactivity with LiveView
  • 🔋 Server-Side Rendered (SSR) React
  • 🦄 Tailwind Support
  • 💀 Dead View Support
  • 🐌 Lazy-loading React Components

Resources

Why LiveReact

Phoenix LiveView enables rich, real-time user experiences with server-rendered HTML. It works by communicating any state changes through a websocket and updating the DOM in realtime. You can get a really good user experience without ever needing to write any client side code.

LiveReact builds on top of Phoenix LiveView to allow for easy client side state management while still allowing for communication over the websocket.

Installation

  1. Add live_react to your list of dependencies in mix.exs:
def deps do
  [
    {:live_react, "~> 0.2.0-rc.0"}
  ]
end
  1. Adjust the setup in mix.exs:
  • For Linux/MacOs
defp aliases do
    [
      setup: ["deps.get", "assets.setup", "npm install --prefix assets", "assets.build"],
    ]
end
  • For Windows
defp aliases do
    [
      setup: ["deps.get", "assets.setup", "cmd --cd assets npm install", "assets.build"],
    ]
end
  1. Run the following in your terminal
mix deps.get
  1. Add import LiveReact in html_helpers/0 inside /lib/<app_name>_web.ex like so:
# /lib/<app_name>_web.ex

defp html_helpers do
  quote do

    # ...

    import LiveReact # <-- Add this line

    # ...

  end
end
  1. Create a package.json file at assets/package.json
{
  "dependencies": {
    "@mrdotb/live-react": "^0.2.1-beta",
    "phoenix": "file:../deps/phoenix",
    "phoenix_html": "file:../deps/phoenix_html",
    "phoenix_live_view": "file:../deps/phoenix_live_view",
    "react": "^18.3.1",
    "react-dom": "^18.3.1"
  }
}
  1. Create a react directory inside assets and add a index.js file
// import and export the react components you want to use in your LiveView
// ex: import { Simple } from "./simple";

// ex: export default { Simple };
export default {};
  1. Add the following to your assets/js/app.js file
...
import components from "../react";
import { getHooks } from  "@mrdotb/live-react";

const hooks = {
  ...getHooks(components),
};

let csrfToken = document
  .querySelector("meta[name='csrf-token']")
  .getAttribute("content");
let liveSocket = new LiveSocket("/live", Socket, {
  hooks: hooks, // <-- pass the hooks
  longPollFallbackMs: 2500,
  params: { _csrf_token: csrfToken },
});
...
  1. For tailwind support, make some addition to content in the assets/tailwind.config.js file
content: [
  ...
    "./react/**/*.jsx", // <- if you are using jsx
    "./react/**/*.tsx" // <- if you are using tsx
],

Examples

Check out the demo website on fly.io to see some examples of what you can do with LiveReact.

Credits

I was inspired by the following libraries:

I had a need for a similar library for React and so I created LiveReact 👍