MCPcopy
hub / github.com/srcbookdev/srcbook / TsConfigProvider

Function TsConfigProvider

packages/web/src/components/use-tsconfig-json.tsx:32–59  ·  view source on GitHub ↗
({ channel, session, children }: ProviderPropsType)

Source from the content-addressed store, hash-verified

30 * An interface for working with tsconfig.json.
31 */
32export function TsConfigProvider({ channel, session, children }: ProviderPropsType) {
33 const [source, setSource] = useState(session['tsconfig.json'] || '');
34 const [validationError, setValidationError] = useState<string | null>(null);
35
36 const onChangeSource = useCallback(
37 (source: string) => {
38 setSource(source);
39
40 const error = getValidationError(source);
41 setValidationError(error);
42
43 if (error === null) {
44 channel.push('tsconfig.json:update', {
45 source,
46 });
47 }
48 },
49 [setSource, channel, setValidationError],
50 );
51
52 const context: TsConfigContextValue = {
53 source,
54 onChangeSource,
55 validationError,
56 };
57
58 return <TsConfigContext.Provider value={context}>{children}</TsConfigContext.Provider>;
59}
60
61export function useTsconfigJson() {
62 const context = useContext(TsConfigContext);

Callers

nothing calls this directly

Calls 2

getValidationErrorFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected