react-query
Version:
Hooks for managing, caching and syncing asynchronous and remote data in React
33 lines (27 loc) • 873 B
JavaScript
module.exports = ({ jscodeshift, utils, root }) => {
const filterUseQueryLikeHookCalls = (node, importIdentifiers, hooks) => {
for (const hook of hooks) {
const selector = utils.getSelectorByImports(importIdentifiers, hook)
if (utils.isFunctionCallOf(node, selector)) {
return true
}
}
return false
}
const findUseQueryLikeHookCalls = (importIdentifiers, hooks) =>
root
// First, we need to find all call expressions.
.find(jscodeshift.CallExpression, {})
// Then we narrow the collection to the `useQuery` like hook calls.
.filter(node =>
filterUseQueryLikeHookCalls(node.value, importIdentifiers, hooks)
)
const execute = (hooks, replacer) => {
findUseQueryLikeHookCalls(utils.locateImports(hooks), hooks).replaceWith(
replacer
)
}
return {
execute,
}
}