1
Fork 0
mirror of https://github.com/Steffo99/bluelib.git synced 2024-12-22 19:44:21 +00:00

🐛 Memoize optionComponents

This commit is contained in:
Steffo 2021-10-11 17:42:41 +02:00
parent 9ae9ef4364
commit 93fd8054ed
Signed by: steffo
GPG key ID: 6965406171929D01
2 changed files with 13 additions and 2 deletions

View file

@ -34,12 +34,17 @@ export function FormMultiselect({label, validity, pairProps, labelProps, onSimpl
[onSimpleChange, options]
)
const optionComponents = React.useMemo(
() => Object.keys(options).map(key => <Multiselect.Option value={key} key={key}/>),
[options],
)
return (
<FormPair
label={<FormLabel {...labelProps}>{label}</FormLabel>}
input={
<Multiselect onSimpleChange={onSimpleChangeWrapped} {...props}>
{Object.keys(options).map(key => <Multiselect.Option value={key} key={key}/>)}
{optionComponents}
</Multiselect>
}
validity={validity}

View file

@ -3,6 +3,7 @@ import * as ReactDOM from "react-dom"
import * as Types from "../../types"
import {BaseElement} from "../BaseElement"
import mergeClassNames from "classnames"
import {Multiselect} from "../inputs/Multiselect"
import {FormPair, FormPairProps} from "./FormPair";
import {FormLabel, FormLabelProps} from "./FormLabel";
import {Select, SelectProps} from "../inputs/Select";
@ -33,12 +34,17 @@ export function FormSelect({label, validity, options, pairProps, labelProps, onS
[onSimpleChange, options]
)
const optionComponents = React.useMemo(
() => Object.keys(options).map(key => <Select.Option value={key} key={key}/>),
[options],
)
return (
<FormPair
label={<FormLabel {...labelProps}>{label}</FormLabel>}
input={
<Select onSimpleChange={onSimpleChangeWrapped} {...props}>
{Object.keys(options).map(key => <Select.Option value={key} key={key}/>)}
{optionComponents}
</Select>
}
validity={validity}