UNPKG

@builder.io/mitosis

Version:

Write components once, run everywhere. Compiles to Vue, React, Solid, and Liquid. Import code from Figma and Builder.io

31 lines (29 loc) 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.contextToReact = void 0; const get_state_object_string_1 = require("../../helpers/get-state-object-string"); const standalone_1 = require("prettier/standalone"); const contextToReact = (options = { typescript: false, preact: false }) => ({ context }) => { let str = ` import { createContext } from '${options.preact ? 'preact' : 'react'}'; export default createContext${options.typescript ? '<any>' : ''}(${(0, get_state_object_string_1.stringifyContextValue)(context.value)}) `; if (options.format !== false) { try { str = (0, standalone_1.format)(str, { parser: 'typescript', plugins: [ require('prettier/parser-typescript'), // To support running in browsers ], }); } catch (err) { if (process.env.NODE_ENV !== 'test') { console.error('Format error for file:', str); } throw err; } } return str; }; exports.contextToReact = contextToReact;