Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-itertools

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-itertools

A suite of tools for manipulating React children

  • 0.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

React Itertools

A suite of tools for manipulating React children

What is this? 🧐

A suite of tools for manipulating React children: each, filter, find, groupBy, map, reduce.

React.Children.map and React.Children.forEach provided by the React Children API iterate shallowly. The utilities in this library will descend the child tree and visit every child.

Installation & Usage 📦

  1. Add this package to your project:
    • yarn add react-itertools

Just trying things out or want to skip the build step? Use the unpkg URL:

<script src="https://unpkg.com/react-itertools/dist/index.production.js"></script>

Example

Try the CodeSandbox Example!

import { map } from "react-itertools";
import { isValidElement } from "react";

const MapExample = ({ children }) => {
  const fn = (el) => {
    return (
      <div
        style={{
          border: "1px solid black",
          padding: "10px",
          backgroundColor: "blanchedalmond",
        }}
      >
        {isValidElement(el) && el.props.children}
      </div>
    );
  };
  return <>{map(children, fn)}</>;
};

export default function App() {
  return (
    <>
      <p>
        `map` recursively iterates through all `children` and returns the
        transformed result of applying `fn` to each child.
      </p>
      <p>Recurses depth first, post-order.</p>
      <MapExample>
        <div>
          <div>
            <div />
            <div />
          </div>
          <div>
            <div />
            <div />
          </div>
        </div>
      </MapExample>
    </>
  );
}

Highlights

🎁 Zero run time dependencies

🦶 Small footprint

🌲 Tree shakeable

🪐 Isomorphic / Universal -- safe to run in any JS context: the browser or on a server

Contributing 👫

PR's and issues welcomed! For more guidance check out CONTRIBUTING.md

Licensing 📃

See the project's MIT License.

Keywords

FAQs

Package last updated on 17 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc