getOverriddenSection function
The
getOverriddenSection function lets you customize sections in your FastStore project without altering its core components and behavior. Instead, it returns a new React component representing the customized section.This allows the creation of multiple overrides based on native components, enabling precise adjustments to specific parts of a section without affecting the rest.
Usage example
Imagine an Alert section with an icon. You want to make the icon bolder without changing anything else.
getOverriddenSection allows you to target just the Icon component.
_23import { getOverriddenSection } from '@faststore/core';_23import { AlertSection } from '@faststore/core';_23import styles from './simple-alert.module.scss'_23_23const SimpleAlert = getOverriddenSection({_23// Specify the original section to be overridden_23Section: AlertSection,_23// Add a class for potential styling (optional)_23className: styles.simpleAlert,_23// Define components to override within the section_23components: {_23 // Override the "Icon" component_23 Icon: {_23 // Change only the "props" of the Icon_23 props: {_23 // Set the "weight" prop to "bold"_23 weight: "bold"_23 }_23 }_23}_23});_23_23export default SimpleAlert;
Instructions
Here's how you can use
getOverriddenSection to customize sections within your FastStore project:- Import the
getOverriddenSectionfrom the@faststore/corepackage. - Import the native section from
@faststore/core. In this example, we considered theAlertSection. - Define a new component using the
getOverriddenSectionfunction (e.g.,SimpleAlert). - In the
Sectionparameter of thegetOverriddenSectionfunction, specify the original section. Note that thegetOverriddenSectionuses the originalAlertSectionas the base for customization. - (Optional) Add a
classNamefor styling the section. - In the
componentsparameter of thegetOverriddenSectionfunction, declare the components you wish to override (e.g.,Icon). - Set the new props for the specified component. In this example, we overrode the weight prop to
boldwithin the Icon's props.
Additional props can be applied to the overridden section. Refer to the List of native sections and overridable components to check the available props for each component.
Parameters
override
Define how to override the native section. This parameter can have the following properties:
| Properties | Description |
|---|---|
Section | React component representing the overridden section. |
components | An object containing overrides for specific components within the section. The keys of this object should match the component names used in the section, and the values should be objects defining overrides for those components. For more details on overrides, refer to Overriding components props and Overriding a component. |
className | Property that behaves similarly to React's className. |