import React, { StrictMode, useState } from 'react' import { createRoot } from 'react-dom/client' import { useUnstrictEffect as useEffect } from './useUnstrictEffect' const ApiTest = function ({ path, method, params }) { const [ result, setResult ] = useState(null) useEffect(() => { 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 }) return () => { return } }, []) return (