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

nimm-react

v1.3.0

Published

React engine on the server

Downloads

33

Readme

NIMM-REACT

React works great on the client why not use it on the server? Now you can.

const {
    root, 
    component, 
    useState, 
    useEffect, 
    useRef
} = require('nimm-react');

install

npm install --save nimm-react

what is supported

root

This is where it all starts similar to ReactDOM.render. You can pass in multiple components. Returns destructor object.

const destructor = root(
    component(fn1),
    component(fn2),
    component(fn3)
); // start

destructor.shutdown(); // this will shut down the system.

component

Component on the server would represent a unit of activity. This takes a function reference and an object for props. No class components. Component will rerender if any props differ by reference or if internal hook queued a rerender. Component can return another component, an array of components or nothing.

function animals() {
    const dogprops = useDog();
    const catprops = useCat();
    return [
        component(dog, {...dogprops}),
        component(cat, {...catprops}),
    ]
}

root(component(animals))

useState

This functions just like useState hook (https://reactjs.org/docs/hooks-state.html) except this will also expose a 3rd prop which, when called, will force reload the state. This is usefull when dealing with modules that rely on reference integrity instead of state.

const _model = require('3rd-party-module');
function useModel() {
    const [model, setModel, rerun] = useState(_model);

    const update(prop, val) {
        model[prop]=val;
        rerun();
    }

    return [model, update];
}

Given the simplicity of the engine you can call setVal in the body of the component. The component will queue the update and rerender based on setImmediate.

Setting value is possible using a function. Just like in React this will update the state in order queued.

const [a,setA]=useState(1);
setA(async a=> { // a is 1 and returns 2;
    await new Promise(res=>setTimeout(res,1000))

    return a+1;
})
setA(a=> { // a is 2  and returns 3;
    return a+1;
}) 

Use State also exposes the guts of the hook as a 4th variable.

useEffect

Just like useEffect in React https://reactjs.org/docs/hooks-state.html. Keep in mind that destructors will run immidiately before a new effect hook runs. By that time the never version of a component has already run and 'rendered'.

useRef

Just like useRef in React https://reactjs.org/docs/hooks-effect.html

useCallback

Juse like useCallback in React https://reactjs.org/docs/hooks-reference.html#usecallback

useResetableState

If you think about it, useCallback is just like useState but with ability to reset it. So there you go, enjoy.

const [val, setVal, _rerun, _guts] = useResetableState(img.username, [img.id]);