html-react-parser 5.0.10 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -196,6 +196,19 @@ parse('<p id="replace">text</p>', {
196
196
  });
197
197
  ```
198
198
 
199
+ The second argument is the index:
200
+
201
+ ```ts
202
+ parse('<br>', {
203
+ replace(domNode, index) {
204
+ console.assert(typeof index === 'number');
205
+ },
206
+ });
207
+ ```
208
+
209
+ > [!NOTE]
210
+ > The index will restart at 0 when traversing the node's children so don't rely on index being a unique key.
211
+
199
212
  #### replace with TypeScript
200
213
 
201
214
  For TypeScript, you'll need to check that `domNode` is an instance of domhandler's `Element`:
@@ -2666,7 +2666,7 @@
2666
2666
  var node = nodes[index];
2667
2667
  // replace with custom React element (if present)
2668
2668
  if (hasReplace) {
2669
- var replaceElement = options.replace(node);
2669
+ var replaceElement = options.replace(node, index);
2670
2670
  if (isValidElement(replaceElement)) {
2671
2671
  // set "key" prop for sibling elements
2672
2672
  // https://react.dev/learn/rendering-lists#rules-of-keys