twentyhq / twenty

Building a modern alternative to Salesforce, powered by the community.
https://twenty.com
Other
20.05k stars 2.23k forks source link

Add an ESLint rule to prevent the usage of useRef other than for HTML elements. #1996

Closed lucasbordeau closed 1 year ago

lucasbordeau commented 1 year ago

Scope & Context

We prefer to avoid having useRef used for state management at Twenty, because we believe that state management should be left to state management libraries.

You can see more in the documentation : https://docs.twenty.com/developer/frontend/best-practices#do-not-use-useref-to-store-state

Current behavior

Actually we can put useRef wherever we want in the codebase.

Expected behavior

We want to prevent this with an ESLint rule that will force useRef to be typed with an HTML element only. Or any other idea if you find something that can tell we're using it only for manipulating a <div> or an <input> (and any other HTML component) in imperative ways.

That way we won't be able to use useRef as a state management solution.

The existing edge cases that can be found in the codebase should be ignored as we'll see how to refactor them later.

gitstart-app[bot] commented 1 year ago

Here is the GitStart Ticket for this issue: https://clients.gitstart.com/twenty/5449/tickets/TWNTY-1996