Replacing imports across a range of changed TypeScript files


I want to replace the use of `import { useDispatch } from 'react-redux'` to a local `import {useAppDispatch} from '../store'` across my entire app. How do I avoid doing this per file?

Currently, I did a search and replace on all `useDispatch()` and replaced them with `useAppDispatch()`. Now I have 89 files to manually go through. That takes forever as search and replace does not work that well across different directory depths. Can IntelliJ help me here and say "Repeat adding this import across a range of changed files"?

I know that in Java there was help in IntelliJ for replacing all usages of Library X with Library Y. This is quite similar, so does such a thing exist?


No, there is no such functionality, search/replace is the only way to go


This took forever, so a reminder to self is to use `jscodeshift` and/or Recast the next time.

Should be quite simple; select the import nodes, remove the usedispatch references (possibly the entire import if empty), introduce a new import where the filepath is converted to a relative path based on some absolute path and the local file.


Please sign in to leave a comment.