react-keyed-flatten-children
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -16,3 +16,3 @@ "use strict"; | ||
acc.push(react_1.cloneElement(node, { | ||
key: keys.join(".") + "." + node.key | ||
key: keys.concat(String(node.key)).join('.') | ||
})); | ||
@@ -19,0 +19,0 @@ } |
@@ -31,3 +31,3 @@ /* Returns React children into an array, flattening fragments. */ | ||
cloneElement(node, { | ||
key: `${keys.join(".")}.${node.key}` | ||
key: keys.concat(String(node.key)).join('.') | ||
}) | ||
@@ -34,0 +34,0 @@ ); |
{ | ||
"name": "react-keyed-flatten-children", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Flattens React children and fragments to an array with predictable and stable keys", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# react-keyed-flatten-children | ||
[![Build Status](https://travis-ci.org/grrowl/react-keyed-flatten-children.svg?branch=master)](https://travis-ci.org/grrowl/react-keyed-flatten-children) | ||
Similar to [React's built-in `Children.toArray` method](https://reactjs.org/docs/react-api.html#reactchildrentoarray), this utility takes children and returns them as an array for introspection or filtering. Different from `toArray`, it will ensure element keys are unique, preserved, and stable between renders, and traverses into fragments and maintains their keys, too. | ||
## getting started | ||
``` | ||
npm install react-keyed-flatten-children | ||
``` | ||
``` | ||
yarn add react-keyed-flatten-children | ||
``` | ||
## why? | ||
@@ -19,3 +31,3 @@ | ||
`react-keyed-flatten-children` is a drop-in replacement for `Children.toArray`. | ||
`react-keyed-flatten-children` is a drop-in replacement for `Children.toArray`. In this example, instead of needing to rely on the child's array index, we can reference the key: | ||
@@ -22,0 +34,0 @@ ```jsx |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8371
7
120