You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.5 KiB
62 lines
1.5 KiB
import React, { createContext } from 'react';
|
|
import { Button, Modal, Space } from 'antd';
|
|
|
|
const ReachableContext = createContext<string | null>(null);
|
|
const UnreachableContext = createContext<string | null>(null);
|
|
|
|
const config = {
|
|
title: 'Use Hook!',
|
|
content: (
|
|
<>
|
|
<ReachableContext.Consumer>{(name) => `Reachable: ${name}!`}</ReachableContext.Consumer>
|
|
<br />
|
|
<UnreachableContext.Consumer>{(name) => `Unreachable: ${name}!`}</UnreachableContext.Consumer>
|
|
</>
|
|
),
|
|
};
|
|
|
|
const App: React.FC = () => {
|
|
const [modal, contextHolder] = Modal.useModal();
|
|
|
|
return (
|
|
<ReachableContext.Provider value="Light">
|
|
<Space>
|
|
<Button
|
|
onClick={() => {
|
|
modal.confirm(config);
|
|
}}
|
|
>
|
|
Confirm
|
|
</Button>
|
|
<Button
|
|
onClick={() => {
|
|
modal.warning(config);
|
|
}}
|
|
>
|
|
Warning
|
|
</Button>
|
|
<Button
|
|
onClick={() => {
|
|
modal.info(config);
|
|
}}
|
|
>
|
|
Info
|
|
</Button>
|
|
<Button
|
|
onClick={() => {
|
|
modal.error(config);
|
|
}}
|
|
>
|
|
Error
|
|
</Button>
|
|
</Space>
|
|
{/* `contextHolder` should always be placed under the context you want to access */}
|
|
{contextHolder}
|
|
|
|
{/* Can not access this context since `contextHolder` is not in it */}
|
|
<UnreachableContext.Provider value="Bamboo" />
|
|
</ReachableContext.Provider>
|
|
);
|
|
};
|
|
|
|
export default App;
|
|
|