React
This documentation will cover all React dedicated APIs provided by the Front-Commerce core.
To help you creating the best front-end with React, we've created convenient React hooks and components that you can reuse in your application.
useConditionalCallOnMount
Execute a callback when component is mounted if a condition is met.
useConditionalCallOnMount(condition, callback);
Arguments:
Name | Type | Description |
---|---|---|
condition | boolean | Specify if the callback must be executed |
callback | function | A function that must be executed if condition is true |
Example:
import { useConditionalCallOnMount } from "@front-commerce/core/react";
const AcmeComponent = ({ props }) => {
const logOnMount = () => {
console.log("I am mounted");
};
useConditionalCallOnMount(props.shouldLogOnMounted, logOnMount);
return <div>Acme Component</div>;
};
useIsMount
A variable that return true
or false
depending of the component mount status
useIsMount();
Return: boolean
Example:
import { useIsMount } from "@front-commerce/core/react";
const AcmeComponent = ({ props }) => {
const isMounted = useIsMount();
return (
<div>
{isMounted ? "Component is mounted" : "Component isn't mounted yet"}
</div>
);
};
useItemsValidityCheck
We recommend you to don't use this API in your application (unless you have a specific use-case that can match this method behaviour).
Return an object to tell the status of validty of an array (mostly used in the context of cart items).
useItemsValidityCheck(items);
Arguments:
Name | Type | Description |
---|---|---|
items | Array | an array of object that have a property named valid |
Return
Object
:
Name | Type | Description |
---|---|---|
allValidityResolved | boolean | all items contains a valid property |
hasValid | boolean | array contain at least one item with valid property |
allValid | boolean | all items have valid property with value true |
useCallbackModal
Manage interactions with a modal and its state.
const modalCallback = useCallbackModal();
Return
Object
:
Name | Type | Description |
---|---|---|
isOpen | boolean | modal state (closed or opened ) |
onRequestClose | function | method that must be passed as prop when modal request a close |
onSuccess | function | method that must be passed as prop when modal action succeed |
openCallbackModal | function | method that is the callback after modal cycle execution |
Example : see
useEnsureLoggedInPromise.jsx
NoPermissionProvider
Component context provider.
<NoPermissionProvider>
<MyChildrenComponent />
</NoPermissionProvider>