Skip to content

Instantly share code, notes, and snippets.

@elderbas
Created May 5, 2021 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elderbas/fab8e8123228faa113f66ba889e22891 to your computer and use it in GitHub Desktop.
Save elderbas/fab8e8123228faa113f66ba889e22891 to your computer and use it in GitHub Desktop.
codemod script to add import statement of `useEffectOnce`
export default (fileInfo, api) => {
const j = api.jscodeshift;
const root = j(fileInfo.source);
const importLine = `import useEffectOnce from 'utils/useEffectOnce';`;
const imports = root.find(j.ImportDeclaration);
const n = imports.length;
j(imports.at(n - 1).get()).insertAfter(importLine); // after the imports
return root.toSource();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment