-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DataGrid] Grid depends on side effects #666
[DataGrid] Grid depends on side effects #666
Conversation
af4fee6
to
14070ff
Compare
30ae55e
to
09982f6
Compare
applyValue, | ||
type, | ||
}) => { | ||
export function FilterInputValue(props: TypeFilterInputValueProps) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for a better typescript support, it would better to keep the type definition otherwise it might just see it as a function instead of a react functional component 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interface FunctionComponent<P = {}> {
(props: PropsWithChildren<P>, context?: any): ReactElement<any, any> | null;
propTypes?: WeakValidationMap<P>;
contextTypes?: ValidationMap<any>;
defaultProps?: Partial<P>;
displayName?: string;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe none of the added types of FunctionComponent are relevant:
- injects a
children
prop, a prop that might not be supported or even be correct: [Tooltip] TypeScript issue with children type and React.FunctionComponent material-ui#23634. - displayName is harmful most of the time (increase bundle size, better alternatives available)
- defaultProps is on its way to deprecation
- contextTypes is legacy
- propTypes isn't relevant with types
I would be in favor of following @eps1lon's point in mui/material-ui#23634 (comment)
This fix #644 (comment)
https://babeljs.io/docs/en/babel-plugin-transform-react-constant-elements is used to optimize the rendering, it moves constant React elements to the upper scope, outside of the React function. So that when the component rerenders, the reference to the React element is identifical, this allows React to skip the rendering of the element, it similar to using React.memo.
However, the data grid relies on a side effect, it depends on its parent to systematically render its children to read the latest value of the grid state and correctly update the DOM.
This is a temporary workaround until we refactor the way the state of the grid is handled. State changes should propagate regardless of React rendering pruning (component memorization or element reference equality).