Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@shopify/react-universal-provider
Advanced tools
Factory function and utilities to create self-serializing/deserializing provider that works for isomorphic applications.
@shopify/react-universal-provider
Factory function and utilities to create self-serializing/deserializing provider that works for isomorphic applications.
$ yarn add @shopify/react-universal-provider
A universal provider is a React component that leverages the useSerialized()
hook from @shopify/react-html
to handle both serializing data during server rendering, and deserializing it on the client. The components often render React.context()
providers to make their serialized state available to the rest of the app they're rendered in.
Consider the I18nUniversalProvider
. In the server you may want to set the locale based on the Accept-Language
header. The client needs to be informed of this somehow to make sure React can render consistently. Traditionally you might do something like:
Accept-Language
header in your node serverI18nManager
with that locale<Serialize name="locale" />
component in the DOM you send to the clientgetSerialized('locale')
in your client entry point for your localeI18nManager
with that locale<I18nProvider />
with the manager from propsWith universal provider you would instead:
Accept-Language
header in your node serverI18nUniversalProvider
with the locale from propsSince universal provider handle the details of serialization they allow you to remove code from your client/server entry points and instead let the react app itself handle those concerns.
This package provide a function which can be use to create a universal provider given a React Context object. It is particularly useful for simple object or primitive that need to be sync up between the server and client.
The list below show a few packages with more complex universal provider:
@shopify/react-app-bridge-universal-provider @shopify/react-csrf-universal-provider @shopify/react-graphql-universal-provider` @shopify/react-i18n-universal-provider
createUniversalProvider
The function takes a unique id and a React Context object.
The resulting Provider takes children and a data prop.
interface Props<Value> {
value?: Value;
children?: React.ReactNode;
}
//ApiKeyUniversalProvider.tsx
import {createContext} from 'react';
import {createUniversalProvider} from '@shopify/react-universal-provider';
export const ApiKeyContext = createContext<string | null>(null);
export const ApiKeyUniversalProvider = createUniversalProvider(
'api-key',
ApiKeyContext,
);
// App.tsx
import {ApiKeyProvider} from './ApiKeyProvider';
function App({apiKey}: {apiKey?: string}) {
return (
<ApiKeyProvider value={apiKey}>{/* rest of the app */}</ApiKeyProvider>
);
}
FAQs
Factory function and utilities to create self-serializing/deserializing providers that work for isomorphic applications
The npm package @shopify/react-universal-provider receives a total of 4,564 weekly downloads. As such, @shopify/react-universal-provider popularity was classified as popular.
We found that @shopify/react-universal-provider demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.