MCPcopy
hub / github.com/facebook/react / Input

Function Input

compiler/apps/playground/components/Editor/Input.tsx:37–180  ·  view source on GitHub ↗
({errors, language}: Props)

Source from the content-addressed store, hash-verified

35};
36
37export default function Input({errors, language}: Props): JSX.Element {
38 const [monaco, setMonaco] = useState<Monaco | null>(null);
39 const store = useStore();
40 const dispatchStore = useStoreDispatch();
41
42 // Set tab width to 2 spaces for the selected input file.
43 useEffect(() => {
44 if (!monaco) return;
45 const uri = monaco.Uri.parse(`file:///index.js`);
46 const model = monaco.editor.getModel(uri);
47 invariant(model, 'Model must exist for the selected input file.');
48 renderReactCompilerMarkers({
49 monaco,
50 model,
51 details: errors,
52 source: store.source,
53 });
54 }, [monaco, errors, store.source]);
55
56 useEffect(() => {
57 /**
58 * Ignore "can only be used in TypeScript files." errors, since
59 * we want to support syntax highlighting for Flow (*.js) files
60 * and Flow is not a built-in language.
61 */
62 if (!monaco) return;
63 monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
64 diagnosticCodesToIgnore: [
65 8002,
66 8003,
67 8004,
68 8005,
69 8006,
70 8008,
71 8009,
72 8010,
73 8011,
74 8012,
75 8013,
76 ...(language === 'flow'
77 ? [7028 /* unused label */, 6133 /* var declared but not read */]
78 : []),
79 ],
80 noSemanticValidation: true,
81 // Monaco can't validate Flow component syntax
82 noSyntaxValidation: language === 'flow',
83 });
84 }, [monaco, language]);
85
86 const handleChange: (value: string | undefined) => void = async value => {
87 if (!value) return;
88
89 dispatchStore({
90 type: 'updateSource',
91 payload: {
92 source: value,
93 },
94 });

Callers

nothing calls this directly

Calls 4

useStateFunction · 0.90
useEffectFunction · 0.90
useStoreFunction · 0.85

Tested by

no test coverage detected