Skip to content

Commit 0e66c82

Browse files
author
wenxuan.feng
committed
chore: optimized select
1 parent f30d61b commit 0e66c82

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
1-
import { ChangeEvent } from 'react';
21
import ListItem from '@mui/material/ListItem';
3-
import TextField from '@mui/material/TextField';
42
import FormControl from '@mui/material/FormControl';
3+
import Select, { SelectChangeEvent } from '@mui/material/Select';
4+
import MenuItem from '@mui/material/MenuItem';
55
import { useDispatch, useStore } from '../../store';
66

77
const BaseUrlControls = () => {
88
const store = useStore();
99
const dispatch = useDispatch();
10-
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
10+
11+
const handleChange = (e: SelectChangeEvent<string>) => {
1112
dispatch({ type: 'baseUrl', payload: e.target.value });
1213
}
14+
1315
return (
1416
<ListItem>
1517
<FormControl fullWidth>
16-
<TextField
18+
<Select
1719
value={store.baseUrl}
1820
fullWidth
19-
label="base URL"
20-
placeholder='https://www.okx.com'
21+
label="Base URL"
2122
onChange={handleChange}
22-
/>
23+
>
24+
<MenuItem value="https://www.okx.com">https://www.okx.com</MenuItem>
25+
<MenuItem value="https://beta.okex.org">https://beta.okex.org</MenuItem>
26+
<MenuItem value="http://127.0.0.1:3000">http://127.0.0.1:3000</MenuItem>
27+
</Select>
2328
</FormControl>
2429
</ListItem>
2530
);
2631
};
2732

28-
export default BaseUrlControls;
33+
export default BaseUrlControls;

src/store/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const initialState = {
1515
}
1616
type Action = {
1717
type: string;
18+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1819
payload: any;
1920
}
2021
const reducer = (state: typeof initialState, action: Action) => {
@@ -74,13 +75,18 @@ const reducer = (state: typeof initialState, action: Action) => {
7475
}
7576
}
7677

78+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7779
export const StoreContext = createContext<{ store: typeof initialState, dispatch: Dispatch<any> } | null>(null);
7880

7981
export const useStore = () => {
82+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
83+
// @ts-expect-error
8084
return useContext(StoreContext).store;
8185
};
8286

8387
export const useDispatch = () => {
88+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
89+
// @ts-expect-error
8490
return useContext(StoreContext).dispatch;
8591
}
8692

0 commit comments

Comments
 (0)