microsoft / microsoft/TypeScript
[Meta] Refactors of React hooks
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
Search Terms
refactor, react, hooks
Suggestion
Provide a series of refactors about react hooks.
Use Cases
In my recently works. I have alway Wrap function, value declarations, expressions into React.useMemo or React.useCallback.
And I must find all the depends on the selection. And always missing some deps. It's not a good experience.
Could we provide some refactors to wrap something into well-known react hooks?
I'm not sure where's the bar of patterns we are allowed. but we have already had something like 'react-jsx'.
Examples
const Comp = props => {
const value = props.a + props.b;
const handleClick = () => {
console.log('foo', value)
}
return <div onClick={handleClick}><SomeHeavyComponent value={value}/></div>
}
- When I select
props.a + props.b, convert into
React.useMemo(() => props.a + props.b, [props.a, props.b]);
- When I select
handleClickor the lambda, convert into
const handleClick = React.userCallback() => {
console.log('foo', value)
}, [value])
- When I select
<SomeHeavyComponent value={value}/>, convert into
React.useMemo(() => (<SomeHeavyComponent value={value}/>), [value])
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Das Issue nennt keine Dateien, Tests oder Einstiegspunkte; kläre zunächst, welche React-Hook-Muster und Abhängigkeitsauswahlen im Umfang liegen. Erledigt wäre die Aufgabe, wenn ein vereinbarter Mustersatz und beobachtbares Refactoring-Verhalten für die useMemo-, useCallback- und JSX-Beispiele vorliegen und Tests für diese Fälle definiert sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- react, typescript
- Bereich
- frontend
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100