algolia / instantsearch

⚑️ Libraries for building performant and instant search and recommend experiences with Algolia. Compatible with JavaScript, TypeScript, React and Vue.

Home Page:https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

useRefinementList: eslint fails with error "Avoid referencing unbound methods which may cause unintentional scoping of this"

VitaliyPotapov opened this issue Β· comments

πŸ› Current behavior

When using useRefinementList as per documentation there is @typescript-eslint error:

Avoid referencing unbound methods which may cause unintentional scoping of `this`

πŸ” Steps to reproduce

  1. enable @typescript-eslint/recommended-requiring-type-checking in the project
  2. use the following code:
    const { refine } = useRefinementList({ attribute: 'brand' });
  3. run eslint and see output:
    Error: Avoid referencing unbound methods which may cause unintentional scoping of `this`.
    If your function does not access `this`, you can annotate it with `this: void`, or consider using an arrow function instead.  @typescript-eslint/unbound-method
    

Live reproduction

https://codesandbox.io/embed/heuristic-chihiro-f2nv7x?fontsize=14&hidenavigation=1&theme=dark

πŸ’­ Expected behavior

Eslint check pass

Package version

algoliasearch 4.16.0 react-instantsearch-hooks-web 6.42.0

Operating system

macOS 13.1

Browser

Chrome/112.0.0.0

Code of Conduct

  • I agree to follow this project's Code of Conduct

The sandbox you shared doesn't have eslint configured, and is also not using useRefinementList as far as I can tell.

Could you share this somewhere it actually reproduces please? Thanks!

Our methods can safely be restructured, so I'm guessing this is somehow a false positive, although I'm not suer what we'd need to change to avoid typescript-eslint thinking the method loses its binding.

Took me some time though other projects, but #5611 is the solution for this