ExpComponentDataDispatcher
is an integrated feature that facilitates the management and proper display of API data. It relies on the foundational use of useReducer in React. To understand this functionality, it is important for the user to have a basic knowledge of useReducer
Here, we have three props:
id
modelInternalName
modelKeyForSSR
useReducer
in ExpComponentDataDispatcher
, dataOfComponentDispatcher
stores data, while componentDataDispatcher
is used to set data.
The dispatcher includes three cases along with a default case.
dispatcher
will occur before the API call. In this scenario, the isLoading
property is set to true, and the componentData
is cleared or emptied. This ensures that the component reverts to its initial state with a loader.
componentData
variable and then pass it to the Default Component. It will likely be invoked after the second case i.e fetchingData
. Additionally, the isLoading
property is set to false as we don’t require a loader after obtaining the data.
ContentService
from the experro-storefront
to send an API request that retrieves data from the admin panel. In order to achieve this, we must provide the following values as parameters:
1. parsedContentModel: It contains the ID of the content-model and the current_version_id associated with that specific content-model.
2. modelInternalName: It contains the model internal name of that component. For example, the modelInternalName for the Title-Section is ‘title_section’. All the modelInternalNames are passed through a file named src/utils/constants-model-internal-name.ts
.
3. modelKeyForSSR: The modelKeyForSSR
is used to ensure that each components are identical. String is assigend as value in modelKeyForSSR
4. id: Every component has a unique ID (CSS selector) assigned to ensure their identicity.
Note: Both ‘modelKeyForSSR’ and ‘id’ are used to ensure that each components are identical.
utils/
directory you can find a file link-parser.tsx
.
The ExpLinkParser
is a component which can be used instead of <a/>
tag or the react’s <link/>
tag.
<a/>
tag or react’s <link/>
tag accordingly.
Props
prop | type | description |
---|---|---|
to | String | URL to be re-directed when user clicks on linkParser |
target | String | Give _blank as target prop if you want to open the url in new tab, by default the target will be _self |
className | String | To define custom class using className prop |
dangerouslySetInnerHTML | html | With dangerouslySetInnerHTML you can insert html inside the linkParser tag |
title | String | Title prop to provide a title to the linkParser tag |
onClick | Function | You can also use onClick method with the this prop |
style | linkParserStyle() | You can give style by calling linkParserStyle() function from src/utils/link-parser-style.tsx component. |
src/utils/constants-model-internal-name.ts
.
For example, if we have created a new model in the admin panel named ‘Blog Details’, add a new key-value pair as blog_details: "blog_details"
to the modelInternalName
object in src/utils/constants-model-internal-name.ts
modelInternalName
as it is used to retrieve data from the API. The name should be identical, with all capital letters converted to lowercase and all space between words replaced with underscores. ( _ )getColorDefaultValueObject
can be found in src/utils/color-default-object.ts
file. It requires two parameters.
Note: This function is only utilized in the widget file when the user integrates a color picker within that widget.
expColorObjectParser
is a useful component in src/utils/color-object-parser.ts
when user needs a color picker in their trait. It is utilized in the component file located at src/components/cms-library/component-folder
(e.g., title-section) in the component.tsx (e.g. title-section.tsx) file. Within this file, user receive a prop that contains the color base data, and the expColorObjectParser
function returns the specific color name that the user has selected from the color picker.
Let me provide an example to illustrate its usage:
expColorObjectParser
and it will return the color that the user can utilize as demonstrated above.
src/utils/currency-converter
and can take two arguments: