UseProductCommentContext hook
const productCommentContext = useProductCommentContext();
This hook can be used in content element on product details page. Content elements can access comment information for product displayed on the page.
The useProductCommentContext hook provides info about the product comment for content elements.
Product comments will be shown on the shopping cart page after adding the product to the shopping cart.
This hook returns the object with data or null in case:
- hook is not being used on the product details page.
- user does not have the
USE_CHECKOUT_ITEM_LINE_COMMENTSability. - user does not have the
ORDER_PRODUCTSability. - product is non-orderable.
- product is configurable.
- product variants are presented in the matrix display mode.
The data contains following properties:
| Property | Type | Description |
|---|---|---|
| comment | string | null | The product comment value. |
| isValid | boolean | The product comment validity status. |
| updateComment | (newComment: string | null, isValid: boolean) => void | The callback to update product comment and product comment validity status. |
Example:
const productCommentContext = useProductCommentContext();
if (!productCommentContext)
return null;
const {
comment,
isValid,
updateComment,
} = productCommentContext;