Skip to content

A transform that swaps one component for another #681

Discussion options

You must be logged in to vote

Here's what I hacked together - seems to work OK...

function replaceJSXTags(_config, options) {
  return {
    visitor: {
      JSXOpeningElement(path) {
        if (options[path.node.name.name]) {
          path.node.name.name = options[path.node.name.name];
        }
      },
      JSXClosingElement(path) {
        if (options[path.node.name.name]) {
          path.node.name.name = options[path.node.name.name];
        }
      }
    }
  }
}

module.exports = replaceJSXTags;

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@gregberge
Comment options

@simonhildebrandt
Comment options

Answer selected by gregberge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants