@shopify/react-csrf
TypeScript icon, indicating that this package has built-in type declarations

3.1.0 • Public • Published

@shopify/react-csrf

Build Status Build Status License: MIT npm version npm bundle size (minified + gzip)

Share CSRF tokens throughout a React application.

Installation

yarn add @shopify/react-csrf

Usage

Setup the Provider around all of the application that need to access csrf token.

// App.tsx
import * as React from 'react';
import {CsrfTokenContext} from '@shopify/react-csrf';

function App({token}: {token?: string}) {
  return (
    <CsrfTokenContext.Provider value={token}>
      {/* rest of the app */}
    </CsrfTokenContext.Provider>
  );
}

Access csrf token using useCsrfToken hook:

import React from 'react';
import {useCsrfToken} from '@shopify/react-csrf';

export default function MyToken() {
  const csrfToken = useCsrfToken();
  return <p>My CSRF Token is: {csrfToken}</p>;
}

Readme

Keywords

none

Package Sidebar

Install

npm i @shopify/react-csrf

Weekly Downloads

46,075

Version

3.1.0

License

MIT

Unpacked Size

5.49 kB

Total Files

20

Last publish

Collaborators

  • jaimie.rockburn
  • blittle
  • shopify-admin
  • maryharte
  • crisfmb
  • pmoloney89
  • netlohan
  • st999999
  • justin-irl
  • megswim
  • wcandillon
  • nathanpjf
  • shopify-dep
  • goodforonefare
  • lemonmade
  • vsumner
  • wizardlyhel
  • antoine.grant
  • tsov
  • andyw8-shopify
  • henrytao
  • hannachen
  • vividviolet
  • bpscott