Skip to content

Commit 3e8fc22

Browse files
committed
fix: 切换时value不会改变
1 parent c684f94 commit 3e8fc22

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

packages/design/components/MonacoEditor/Editor.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@ const FILENAME = 'index.tsx';
1515

1616
const MonacoEditor = (props: MocacoEditorProps) => {
1717
const { compilerWorker } = useWorkers();
18-
const [value, onChange] = useControlled<string>(props, {
19-
valuePropName: 'value',
20-
changeName: 'onChange',
21-
defaultValuePropName: 'defaultValue',
22-
});
18+
// const [value, onChange] = useControlled<string>(props, {
19+
// valuePropName: 'value',
20+
// changeName: 'onChange',
21+
// defaultValuePropName: 'defaultValue',
22+
// });
2323
const {
2424
height = 400,
2525
defaultLanguage = CodeType.ts,
2626
path = FILENAME,
2727
theme = ThemeType['Visual Studio Dark'],
2828
modules,
29+
onChange,
30+
defaultValue,
2931
...rest
3032
} = props;
3133

@@ -39,7 +41,7 @@ const MonacoEditor = (props: MocacoEditorProps) => {
3941
type: MessageChangeType.Compile,
4042
data: {
4143
filename: path,
42-
code: value,
44+
code: defaultValue,
4345
modules,
4446
},
4547
});
@@ -64,11 +66,11 @@ const MonacoEditor = (props: MocacoEditorProps) => {
6466
height={height}
6567
path={path}
6668
defaultLanguage={defaultLanguage}
67-
defaultValue={value}
69+
defaultValue={defaultValue}
6870
theme={theme}
6971
onChange={handleEditorChange}
7072
onMount={handleEditorDidMount}
71-
{...omit(rest, ['value', 'onChange'])}
73+
{...rest}
7274
// beforeMount={handleEditorWillMount}
7375
// onValidate={handleEditorValidation}
7476
/>

packages/design/components/MonacoEditor/MultipleEditor.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ const items = [
3535
}`,
3636
},
3737
];
38-
// todo: 1.多文件引入(scss、tsx),引入scss
39-
// 2.代码优化;
38+
// todo: 1. 编译文件的独立性。现在修改css实际走的是tsx的编译
39+
// 2.引入scss
40+
// 3.代码优化;
4041
const MultipleEditor = () => {
4142
const [tabsValue, setTabsValue] = useLocalStorage('tabs', {
4243
defaultValue: items,
@@ -52,7 +53,7 @@ const MultipleEditor = () => {
5253
modules={tabsValue}
5354
path={String(item.label)}
5455
defaultLanguage={item.language}
55-
value={item.value}
56+
defaultValue={item.value}
5657
onChange={(value) => {
5758
const prevTabValue = tabsValue;
5859
const activeTab = _find(prevTabValue, item.key);

0 commit comments

Comments
 (0)