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

react-component-instance

Package Overview
Dependencies
Maintainers
1
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-component-instance

Get a React class component instance from its DOM Element

latest
Source
npmnpm
Version
0.0.126
Version published
Maintainers
1
Created
Source

react-component-instance

Get a React class component instance from its DOM element

import {
  getInstance,
  findInstanceFor
} from 'react-component-instance'

With @testing-library/react

import {
  render
} from '@testing-library/react'

import {
  getInstance
} from 'react-component-instance'

describe('`getInstance`', () => {
  class Component extends React.Component {
    render () {
      return (
        <div className='grand-parent'>
          <div className='parent'>
            <div className='child'>
              TEXT
            </div>
          </div>
        </div>
      )
    }
  }

  it('gets the instance', () => {
    expect(getInstance(render(
      <Component />
    )))
      .toBeInstanceOf(Component)
  })
})
import {
  render
} from '@testing-library/react'

import {
  findInstanceFor
} from 'react-component-instance'

describe('`findInstanceFor`', () => {
  class Component extends React.Component {
    render () {
      return (
        <div className='grand-parent'>
          <div className='parent'>
            <div className='child'>
              TEXT
            </div>
          </div>
        </div>
      )
    }
  }

  it('gets the instance', () => {
    const {
      container
    } = render(
      <Component />
    )

    const child  = container.querySelector('.child')

    expect(findInstanceFor(child, Component))
      .toBeInstanceOf(Component)
  })
})

Keywords

react

FAQs

Package last updated on 28 Nov 2025

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