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

react-change-props

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-change-props

Mutate(Change) React props, for each element in tree, and replace children.

latest
Source
npmnpm
Version
1.2.0
Version published
Maintainers
1
Created
Source

react-change-props

Mutate(Change) React props, for each element in tree, and replace children.

npm Build Status

Why?

In React, you cannot change this.props of any component, but in case you want to?

Install

npm install react-change-props -S
# or
yarn add react-change-props

Usage

import React from 'react'
import changeProps from 'react-change-props'

const replacer = str => (str && {className: 'my-prefix-' + str})
const newThing = changeProps(
  <div className="a"><p className="b"><span>text</span></p></div>,
  el => replacer(el.props.className)
)

The newThing will be:

<div className="my-prefix-a"><p className="my-prefix-b"><span>text</span></p></div>

The API is easy:

// changeProps(JSX, [replacer])
var newJSX = changeProps(JSX, el => new_props_for_this_el)

If you return { children: <Foo/> } from above replacer, the children elements will be replaced.

The return value of replacer will be passed into Object.assign({}, return_value), so if you return Non-Object, nothing happend.

Notes

React only put Object.freeze when process.env.NODE_ENV==='development', this lib will account the case of development and production.

Keywords

react

FAQs

Package last updated on 17 Mar 2018

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