use-server-effect
useServerEffect is a serverside-rendering friendly wrapper around the useEffect React hook. This package provides a browser shim for compatibility in client-side react.
Last updated 2 months ago by f0x52 .
GPL-3.0 · Repository · Original npm · Tarball · package.json
$ cnpm install use-server-effect 
SYNC missed versions from official npm registry.

useServerEffect

useServerEffect is a serverside-rendering friendly wrapper around the useEffect React hook. This package provides a browser shim for compatibility in client-side react.

For serverside-rendering, you would intercept the require call for this package, and re-render the component after the returned Promise resolves.
This is implemented in Shayu, a static site generator.

The Rules of Hooks still apply.

License, donations

GPL-3.0. If you want to support my work, you can:
Donate using Liberapay

Example

see example.js in the repo:


const React = require("react");
const useServerEffect = require("use-server-effect");

function Test() {
	let [thing, setThing] = React.useState("initial");

	useServerEffect(() => {
		return new Promise((resolve) => {
			setTimeout(() => {
				setThing("changed");
				resolve();
			}, 1000);
		})
	})

	return thing;
}

API

requireTranspile(effect)

  • effect: function that returns a Promise, resolving after the state(s) are set

Changelog

v1.0.0 (????️‍???? June 19, 2020)

  • working implementation

v0.0.1 (????️‍???? June 16, 2020)

  • basic untested implementation, reserve package name to safely override in code

Current Tags

  • 1.0.0                                ...           latest (2 months ago)

3 Versions

  • 1.0.0                                ...           2 months ago
  • 0.0.2                                ...           2 months ago
  • 0.0.1                                ...           2 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |