Socket
Socket
Sign inDemoInstall

use-server-effect

Package Overview
Dependencies
6
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    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.


Version published
Weekly downloads
2
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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

FAQs

Last updated on 18 Jun 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc