New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

use-inside

Package Overview
Dependencies
Maintainers
10
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-inside

[](https://www.npmjs.com/package/use-inside) [](https://bundlephobia.com/result?p=use-inside)

latest
npmnpm
Version
0.2.0
Version published
Weekly downloads
66
-22.35%
Maintainers
10
Weekly downloads
 
Created
Source

🔬 useInside()

useInside() allows a component to be aware if its "inside" the subtree of another component and receive data from it, in the most straightforward, simple way possible.

Usage

Add it to your project:

yarn add use-inside

Use it in your React app:

// App.js

import React from 'react'
import { Inside, useInside } from 'use-inside'

function App() {

  return (
    <>
      <h1>useInside</h1>
      <Inside name="papaya" data={{backgroundColor: 'papayawhip'}}>
        <Greeting />
      </Inside>
    </>
  )
}

function Greeting() {
  const [inside, data] = useInside('papaya')

  return <h2 style={{...data}}>{inside && 'papaya'}</h2>
}

export default App

API

<Inside />

This is the provider component. It should be placed above any component using useInside(). Apart from children, it accepts two other props:

name (required)

The name of the inside context. Required for storing the context into a map for later retrieval.

data

The data passed to the component using useInside(). Accepts any type.

useInside()

This is the hook to be used throughout the app.

It takes a string as a single required param, and returns an array containing the following:

  • inside: A boolean that will be true if the component is in the subtree of the provider Inside component.
  • data: The data passed through the Inside component.

FAQs

Package last updated on 31 Mar 2020

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