我有以下功能组件,它呈现 3 个复选框(Shopify Polaris):
function CustomersList() {
const [selected, setSelected] = useState(['hidden']);
const handleChange = useCallback((value) => setSelected(value), []);
return (
<ChoiceList
allowMultiple
title="Customers:"
choices={[
{
label: 'Customer 1',
value: 'customer1',
},
{
label: 'Customer 2',
value: 'customer2',
},
{
label: 'Customer 3',
value: 'customer3',
}
]}
selected={selected}
onChange={handleChange}
/>
);
}
...和相同的功能。组件在父组件中使用(都在同一个文件中):
class ParentComponent extends Component {
render() {
return (
<Page title="Title">
<Layout>
<Layout.Section>
<Card title="Customers" sectioned>
<CustomersList />
<Subheading>
Selected customers: {customer_value}
</Subheading>
</Card>
</Layout.Section>
</Layout>
</Page>
)
}
}
现在,我的问题是如何从 func 发送和获取客户价值(customer1、customer2 等)。组件到父组件,在这里显示值:Selected customers: {customer_value}
?
谢谢