elierotenberg / elierotenberg/react-traverse

Example needed: Change value of some prop for all uses of some component

Open
#3 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
69
Forks
13
PR merge metrics
No merged PRs in 30d

Description

Say I have ComponentA and ComponentB. ComponentA will render() some arbitrary element tree that includes B at arbitrary locations. I want to change all of the `myValue` props on ComponentB to be prefixed with the value '_'. How can I do this?

I want this:

```
class ComponentA extends React.Component {
render() {
return (





)
}
}
```

to become this:

```
class ComponentA extends React.Component {
render() {
return (





)
}
}
```

Also, the `replaceDivsWithSpans` example from the README uses `DOMElement` in the visitor, but what would I use for a component (not a component element)? Using `ComponentElement` works for e.g. `transformComponents(wrapRender(transformNode))()` but not `transformComponents(wrapRender(transformNode))(ComponentA)`. No method on my visitor gets called (e.g. `ComponentElement`). I'm not sure if this is because I'm using React 15.3?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.