javascript - How to rename a React component prop across all files? - Stack Overflow

I have some ponent like thisconst Component = ({ oldPropName }) => ...which I want to refactor to:

I have some ponent like this

const Component = ({ oldPropName }) => ...

which I want to refactor to:

const Component = ({ newPropName }) => ...

and I want all occurrences of this oldPropName across all files to be changed automatically. Is there way to do this with VSCode?

Essentially same question can be asked as how to rename a destructured function parameter across the files without thinking about React ponents.

I have some ponent like this

const Component = ({ oldPropName }) => ...

which I want to refactor to:

const Component = ({ newPropName }) => ...

and I want all occurrences of this oldPropName across all files to be changed automatically. Is there way to do this with VSCode?

Essentially same question can be asked as how to rename a destructured function parameter across the files without thinking about React ponents.

Share Improve this question asked Nov 7, 2021 at 16:26 wunnlewunnle 791 silver badge5 bronze badges 6
  • Why does search-and-replace not work for you here? – jmargolisvt Commented Nov 7, 2021 at 16:30
  • Does this answer your question? How do I find and replace all occurrences (in all files) in Visual Studio Code? – Randy Casburn Commented Nov 7, 2021 at 16:32
  • @jmargolisvt It doesn not because oldPropName may be a mon prop name like onClick. Search and replace will accidentally change prop names of irrelevant ponents. – wunnle Commented Nov 7, 2021 at 16:37
  • @RandyCasburn Unfortunately not. See the ment above – wunnle Commented Nov 7, 2021 at 16:38
  • According to your question, though, there are no irrelevant ponents. You want to make this change across all ponents. – Andy Commented Nov 7, 2021 at 17:08
 |  Show 1 more ment

2 Answers 2

Reset to default 2

F2 will change all variable occurrences in the code if you disable the following settings:

You can right click the oldPropName and there should be a "Rename Symbol" option or you can use F2. Some languages support rename symbol across files. Press F2 and then type the new desired name and press Enter. All usages of the symbol will be renamed, across files.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745552192a4632627.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信