mirror of
https://github.com/Steffo99/bluelib.git
synced 2024-12-23 03:54:21 +00:00
🐛 Memoize optionComponents
This commit is contained in:
parent
9ae9ef4364
commit
93fd8054ed
2 changed files with 13 additions and 2 deletions
|
@ -34,12 +34,17 @@ export function FormMultiselect({label, validity, pairProps, labelProps, onSimpl
|
||||||
[onSimpleChange, options]
|
[onSimpleChange, options]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const optionComponents = React.useMemo(
|
||||||
|
() => Object.keys(options).map(key => <Multiselect.Option value={key} key={key}/>),
|
||||||
|
[options],
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormPair
|
<FormPair
|
||||||
label={<FormLabel {...labelProps}>{label}</FormLabel>}
|
label={<FormLabel {...labelProps}>{label}</FormLabel>}
|
||||||
input={
|
input={
|
||||||
<Multiselect onSimpleChange={onSimpleChangeWrapped} {...props}>
|
<Multiselect onSimpleChange={onSimpleChangeWrapped} {...props}>
|
||||||
{Object.keys(options).map(key => <Multiselect.Option value={key} key={key}/>)}
|
{optionComponents}
|
||||||
</Multiselect>
|
</Multiselect>
|
||||||
}
|
}
|
||||||
validity={validity}
|
validity={validity}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import * as ReactDOM from "react-dom"
|
||||||
import * as Types from "../../types"
|
import * as Types from "../../types"
|
||||||
import {BaseElement} from "../BaseElement"
|
import {BaseElement} from "../BaseElement"
|
||||||
import mergeClassNames from "classnames"
|
import mergeClassNames from "classnames"
|
||||||
|
import {Multiselect} from "../inputs/Multiselect"
|
||||||
import {FormPair, FormPairProps} from "./FormPair";
|
import {FormPair, FormPairProps} from "./FormPair";
|
||||||
import {FormLabel, FormLabelProps} from "./FormLabel";
|
import {FormLabel, FormLabelProps} from "./FormLabel";
|
||||||
import {Select, SelectProps} from "../inputs/Select";
|
import {Select, SelectProps} from "../inputs/Select";
|
||||||
|
@ -33,12 +34,17 @@ export function FormSelect({label, validity, options, pairProps, labelProps, onS
|
||||||
[onSimpleChange, options]
|
[onSimpleChange, options]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const optionComponents = React.useMemo(
|
||||||
|
() => Object.keys(options).map(key => <Select.Option value={key} key={key}/>),
|
||||||
|
[options],
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormPair
|
<FormPair
|
||||||
label={<FormLabel {...labelProps}>{label}</FormLabel>}
|
label={<FormLabel {...labelProps}>{label}</FormLabel>}
|
||||||
input={
|
input={
|
||||||
<Select onSimpleChange={onSimpleChangeWrapped} {...props}>
|
<Select onSimpleChange={onSimpleChangeWrapped} {...props}>
|
||||||
{Object.keys(options).map(key => <Select.Option value={key} key={key}/>)}
|
{optionComponents}
|
||||||
</Select>
|
</Select>
|
||||||
}
|
}
|
||||||
validity={validity}
|
validity={validity}
|
||||||
|
|
Loading…
Reference in a new issue