React Memberstack is a wrapper around the @memberstack/dom package. It makes it easy to add Memberstack to any React app.
Welcome to the React Memberstack documentation! The Memberstack React Package is a wrapper around the @memberstack/dom package, designed to make it easy to integrate Memberstack into any React application. Memberstack is a platform that provides user authentication, membership management, and other user-centric features.
This documentation assumes that you have a working knowledge of React and React Hooks. If you're new to these technologies, we recommend checking out the official React documentation and this guide on React Hooks before proceeding.
Getting Started
To get started, you'll need to install the Memberstack React package from the npm public registry, or using yarn. Here are the commands to do so:
npminstall@memberstack/react
yarnadd@memberstack/react
Memberstack Provider
After the package has been installed successfully, you can wrap the components that need access to the Memberstack object in the provided MemberstackProvider.
The MemberstackProvider receives a config prop, which contains the memberstack initialization object with DOM modifications.
Memberstack React comes packed with custom hooks. These hooks give you access to Memberstack-related data plus a collection of useful methods for checking out, plan management, and authentication.
useMemberstack
The useMemberstack hook returns a reference to the memberstack instance, created by the MemberstackProvider.
The useCustomerPortal hook returns a method that opens a Stripe-hosted customer billing portal session. Members can update their billing information, view invoices and manage subscriptions inside of the portal.
The useMemberstackModal hook returns the openModal and hideModal methods, which you can use to easily interact with Memberstack's provided modals.
Read the Modals section for more information about the configuration
💡 Although you can directly use the memberstack.openModal method without using the useMemberstackModal hook, the openModal method provided by the hook ensures that the modal always gets loaded once Memberstack has finished initializing. This means that you don't have to make sure that Memberstack is able to open your modal; we take care of that for you.
Memberstack UI components are used to render beautiful views contained within our prebuilt UI collection. These UI components will automatically open as modals when the page loads.
Presents a sign-up view that takes the same properties specified in the useMemberstackModal requirements.
Runs before the onClose when the modal api call is successful
({data,type}) => void
onError
Runs before the onClose when the modal api call is unsuccessful
(error) => void
onClose
Ran every time the modal closes
() => void
<SignUpModal />
Name
Description
Type
planId
An array of plan ids for a user to sign up with.
string[]
Logic Wrapper Components
Memberstack logic wrappers are components that allow you to conditionally render content based on the member’s logged-in state plus a variety of other checks, like plans & permissions.
Allows you to conditionally render content based on the currently authenticated member, their plans, and/or permissions.
Parameters:
allowobject An optional object to give you more control over which members to authorize. By default, only authenticated members have access to the protected components, but you can use the values within the access object to get more specific.
permissionsarray A list of permission names.
plansarray A list of plan ids.
onUnauthorizedfunction | React element(s) A callback function or React element to invoke/render when the member is not authorized.
fallbackReact element A fallback element when Memberstack is loading information before (un)authorizing.