Skip to content

Instantly share code, notes, and snippets.

@romgrk
Created August 23, 2024 04:30
Show Gist options
  • Save romgrk/534bd1b0cf195ff74f3e8e4bddca2f48 to your computer and use it in GitHub Desktop.
Save romgrk/534bd1b0cf195ff74f3e8e4bddca2f48 to your computer and use it in GitHub Desktop.
import * as React from 'react';
import { flushSync } from 'react-dom';
import {
Button,
Container,
Checkbox,
Switch,
Box,
Paper,
TextField,
} from '@mui/material'
function ButtonGroup() {
const [, setState] = React.useState({})
const onClick = () => {
return setState({})
}
return (
<Paper sx={{ backgroundColor: '#121212' }}>
<Button key='1' onClick={onClick} variant='outlined' size='small'>test</Button>
<Button key='2' onClick={onClick} variant='outlined' size='medium'>test</Button>
<Button key='3' onClick={onClick} variant='outlined' size='large'>test</Button>
<Button key='4' onClick={onClick} variant='outlined' size='medium' color='success'>test</Button>
<Button key='5' onClick={onClick} variant='outlined' size='medium' color='error'>test</Button>
</Paper>
)
}
function CheckboxGroup() {
return (
<Paper>
<Checkbox />
<Checkbox />
<Checkbox />
<Checkbox />
<Checkbox />
</Paper>
)
}
function SwitchGroup() {
return (
<Box>
<Switch size="small" />
<Switch size="small" />
<Switch size="small" />
<Switch size="small" />
<Switch size="small" />
</Box>
)
}
function InputGroup() {
return (
<Paper>
<TextField key='1' />
<TextField key='2' />
<TextField key='3' />
<TextField key='4' />
<TextField key='5' />
</Paper>
)
}
export default function Component() {
const [show, setShow] = React.useState(false)
const run = () => {
const results = []
for (let i = 0; i < 20; i++) {
flushSync(() => {
setShow(false)
})
const start = performance.now()
flushSync(() => {
setShow(true)
})
const end = performance.now()
results.push(end - start)
}
console.log(results)
}
return (
<Paper>
<div>
<button onClick={() => setShow(!show)}>toggle</button>
<button onClick={run}>run</button>
</div>
{show &&
<Paper>
<Container>
<ButtonGroup />
<ButtonGroup />
<ButtonGroup />
<ButtonGroup />
<ButtonGroup />
<ButtonGroup />
<ButtonGroup />
<ButtonGroup />
<ButtonGroup />
<ButtonGroup />
</Container>
<Container>
<CheckboxGroup />
<CheckboxGroup />
<CheckboxGroup />
<CheckboxGroup />
<CheckboxGroup />
<CheckboxGroup />
<CheckboxGroup />
<CheckboxGroup />
<CheckboxGroup />
<CheckboxGroup />
</Container>
<Container>
<SwitchGroup />
<SwitchGroup />
<SwitchGroup />
<SwitchGroup />
<SwitchGroup />
<SwitchGroup />
<SwitchGroup />
<SwitchGroup />
<SwitchGroup />
<SwitchGroup />
</Container>
<Container>
<InputGroup />
<InputGroup />
<InputGroup />
<InputGroup />
<InputGroup />
<InputGroup />
<InputGroup />
<InputGroup />
<InputGroup />
<InputGroup />
</Container>
</Paper>
}
</Paper>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment