import React, { StrictMode, useState, useMemo } from 'react' import { createRoot } from 'react-dom/client' import { useUnstrictEffect as useEffect } from './useUnstrictEffect' const ApiTest = function ({ path, method, params }) { const [ submit_enabled, setSubmitEnabled ] = useState(true) const [ result, setResult ] = useState(null) const func_click_submit = useMemo(() => { return () => { setSubmitEnabled(false) let endpoint_full let body if (method === 'GET') { endpoint_full = path + '?' + new URLSearchParams({ p: JSON.stringify(params), }).toString() } else if (method === 'POST') { endpoint_full = path body = JSON.stringify(params) } else { throw `bad method : ${method}` } fetch(endpoint_full, { method, body }).then(async (resp) => { const resp_json = await resp.json() setResult(resp_json) return }).catch(console.error).finally(() => { setSubmitEnabled(true) return }) return } }, []) const jsx_btn_submit = () return (
{'Input'}
{JSON.stringify({ path, method, params }, null, 2)}
{jsx_btn_submit}
{'Output'}
{JSON.stringify(result, null, 2)}
) } const HEIGHT_PANEL_HEADER = `${8*8}px` const DemoStash = function () { return (
{'/stash'}
) } const DemoSearch = function () { return (
{'/search'}
) } const App = function () { return (
) } const render_app = function () { const elem_appstyles = document.createElement('style') elem_appstyles.innerHTML = ` html, body { height: 100%; width: 100%; overflow: hidden; margin: 0px; padding: 0px; border: 0px; } `.trim() document.head.appendChild(elem_appstyles) const elem_root = document.createElement('div') elem_root.style = 'height:100%; width:100%;' document.body.appendChild(elem_root) const func_render_app = () => { const react_root = createRoot(elem_root) react_root.render(( )) return } func_render_app() return {} } export { render_app }