Enable react-compiler eslint to spot antipatterns (#28652)
* Switch to React18 useId Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Enable react-compiler eslint Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix an easy one Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Disable in tests Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix usage of useRef as memoization Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix mutation of external values in hooks Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Make React compiler happy about some frankly non-issues Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix MapMock Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Revert MemberListViewModel.tsx changes and disable linter per line Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Make viewmodel compatible with react-compiler linter - Remove searchQuery ref/state and instead pass this query to the loadMember function. - Now we no longer need a separate search function --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> Co-authored-by: R Midhun Suresh <hi@midhun.dev>
This commit is contained in:
committed by
GitHub
parent
e5ca7954c8
commit
ef1597ff2d
@@ -7,7 +7,7 @@ Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import classNames from "classnames";
|
||||
import React, { useEffect, useRef } from "react";
|
||||
import React, { useMemo } from "react";
|
||||
|
||||
type FlexProps = {
|
||||
/**
|
||||
@@ -40,25 +40,6 @@ type FlexProps = {
|
||||
grow?: string | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set or remove a CSS property
|
||||
* @param ref the reference
|
||||
* @param name the CSS property name
|
||||
* @param value the CSS property value
|
||||
*/
|
||||
function addOrRemoveProperty(
|
||||
ref: React.MutableRefObject<HTMLElement | undefined>,
|
||||
name: string,
|
||||
value?: string | null,
|
||||
): void {
|
||||
const style = ref.current!.style;
|
||||
if (value) {
|
||||
style.setProperty(name, value);
|
||||
} else {
|
||||
style.removeProperty(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A flex child helper
|
||||
*/
|
||||
@@ -71,12 +52,12 @@ export function Box({
|
||||
children,
|
||||
...props
|
||||
}: React.PropsWithChildren<FlexProps>): JSX.Element {
|
||||
const ref = useRef<HTMLElement>();
|
||||
|
||||
useEffect(() => {
|
||||
addOrRemoveProperty(ref, `--mx-box-flex`, flex);
|
||||
addOrRemoveProperty(ref, `--mx-box-shrink`, shrink);
|
||||
addOrRemoveProperty(ref, `--mx-box-grow`, grow);
|
||||
const style = useMemo(() => {
|
||||
const style: Record<string, any> = {};
|
||||
if (flex) style["--mx-box-flex"] = flex;
|
||||
if (shrink) style["--mx-box-shrink"] = shrink;
|
||||
if (grow) style["--mx-box-grow"] = grow;
|
||||
return style;
|
||||
}, [flex, grow, shrink]);
|
||||
|
||||
return React.createElement(
|
||||
@@ -88,7 +69,7 @@ export function Box({
|
||||
"mx_Box--shrink": !!shrink,
|
||||
"mx_Box--grow": !!grow,
|
||||
}),
|
||||
ref,
|
||||
style,
|
||||
},
|
||||
children,
|
||||
);
|
||||
|
||||
@@ -7,7 +7,7 @@ Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import classNames from "classnames";
|
||||
import React, { useEffect, useRef } from "react";
|
||||
import React, { useMemo } from "react";
|
||||
|
||||
type FlexProps = {
|
||||
/**
|
||||
@@ -64,15 +64,16 @@ export function Flex({
|
||||
children,
|
||||
...props
|
||||
}: React.PropsWithChildren<FlexProps>): JSX.Element {
|
||||
const ref = useRef<HTMLElement>();
|
||||
const style = useMemo(
|
||||
() => ({
|
||||
"--mx-flex-display": display,
|
||||
"--mx-flex-direction": direction,
|
||||
"--mx-flex-align": align,
|
||||
"--mx-flex-justify": justify,
|
||||
"--mx-flex-gap": gap,
|
||||
}),
|
||||
[align, direction, display, gap, justify],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
ref.current!.style.setProperty(`--mx-flex-display`, display);
|
||||
ref.current!.style.setProperty(`--mx-flex-direction`, direction);
|
||||
ref.current!.style.setProperty(`--mx-flex-align`, align);
|
||||
ref.current!.style.setProperty(`--mx-flex-justify`, justify);
|
||||
ref.current!.style.setProperty(`--mx-flex-gap`, gap);
|
||||
}, [align, direction, display, gap, justify]);
|
||||
|
||||
return React.createElement(as, { ...props, className: classNames("mx_Flex", className), ref }, children);
|
||||
return React.createElement(as, { ...props, className: classNames("mx_Flex", className), style }, children);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user