Components
ScandiPWA React components are reusable pieces of UI logic
The .component File
// no need to import React - it is automatically imported
// import order should be kept consistent
// library imports first
import PropTypes from 'prop-types';
import { PureComponent } from 'react';
// absolute imports from other directories are second
import TextPlaceholder from 'Component/TextPlaceholder';
import { PriceType } from 'Type/ProductList';
// relative imports from the same directory are last
import './ProductPrice.style';
// ^ the .component file is responsible for importing the stylesheet
// namespaces are necessary for the plugin mechanism to work
/** @namespace Component/ProductPrice/Component */
export class ProductPrice extends PureComponent {
// ^ note that we exported the component's class in a named export.
// only the default export will actually be used when rendering
// the component, but we always export the class itself so that
// it can be used when extending the component in a child theme.
// this becomes important if the default export is wrapped in a HOC
// such as withRouter, making it impossible to extend as a class
renderPlaceholder() {
return (
<p block="ProductPrice" aria-label="Product Price">
<TextPlaceholder length="custom" />
</p>
);
}
renderCurrentPrice() {...}
renderOldPrice() {...}
renderSchema() {...}
render() {
// [...]
if (!final_price || !regular_price) {
return this.renderPlaceholder();
}
return (
<p block="ProductPrice">
{ this.renderCurrentPrice() }
{ this.renderOldPrice() }
{ this.renderSchema() }
</p>
);
}
}
export default ProductPrice;A Common .component Pattern: Render Maps
The .container File
A Common .container Pattern: containerProps
A Common .container Pattern: containerFunctions
Example .container
The .config File
The .style File
The index.js File
Last updated