remove Provider

master
Avraham Sakal 2 years ago
parent 2fb6e8506b
commit f54b42d0ad

32
dist/index.js vendored

@ -36589,22 +36589,6 @@ var useStore = (options) => {
const store = (0, import_react2.useContext)(StoreContext); const store = (0, import_react2.useContext)(StoreContext);
return (options == null ? void 0 : options.store) || store || getDefaultStore(); return (options == null ? void 0 : options.store) || store || getDefaultStore();
}; };
var Provider = ({
children,
store
}) => {
const storeRef = (0, import_react2.useRef)();
if (!store && !storeRef.current) {
storeRef.current = createStore();
}
return (0, import_react2.createElement)(
StoreContext.Provider,
{
value: store || storeRef.current
},
children
);
};
var isPromiseLike2 = (x) => typeof (x == null ? void 0 : x.then) === "function"; var isPromiseLike2 = (x) => typeof (x == null ? void 0 : x.then) === "function";
var use = import_react2.default.use || ((promise) => { var use = import_react2.default.use || ((promise) => {
if (promise.status === "pending") { if (promise.status === "pending") {
@ -36684,11 +36668,13 @@ function useAtom(atom2, options) {
// src/Picker.tsx // src/Picker.tsx
var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1); var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
function Picker({ $options, $isLoading, $url, $isEnabled, $selectedOption }) { function Picker({
$options = $options || (0, import_react3.useMemo)(() => atom([]), []); $url,
$isLoading = $isLoading || (0, import_react3.useMemo)(() => atom(true), []); $options = (0, import_react3.useMemo)(() => atom([]), []),
$isEnabled = $isEnabled || (0, import_react3.useMemo)(() => atom(true), []); $isLoading = (0, import_react3.useMemo)(() => atom(true), []),
$selectedOption = $selectedOption || (0, import_react3.useMemo)(() => atom(""), []); $isEnabled = (0, import_react3.useMemo)(() => atom(true), []),
$selectedOption = (0, import_react3.useMemo)(() => atom(""), [])
}) {
const url = useAtomValue($url); const url = useAtomValue($url);
const options = useAtomValue($options); const options = useAtomValue($options);
const isLoading = useAtomValue($isLoading); const isLoading = useAtomValue($isLoading);
@ -36703,14 +36689,14 @@ function Picker({ $options, $isLoading, $url, $isEnabled, $selectedOption }) {
fetch(url).then((x) => x.json()).catch((err) => ["AAPL", "MSFT", "GOOG"]).then(optionsFetched); fetch(url).then((x) => x.json()).catch((err) => ["AAPL", "MSFT", "GOOG"]).then(optionsFetched);
} }
}, [url, isEnabled]); }, [url, isEnabled]);
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Provider, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "Loading..." }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("select", { value: selectedOption, onChange: (e) => { return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "Loading..." }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("select", { value: selectedOption, onChange: (e) => {
setSelectedOption(e.target.value); setSelectedOption(e.target.value);
}, children: [ }, children: [
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: "" }, ""), /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: "" }, ""),
options.map( options.map(
(date) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: date, children: date }, date) (date) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: date, children: date }, date)
) )
] }) }) }); ] }) });
} }
// src/App.module.css // src/App.module.css

@ -1,5 +1,5 @@
import { useEffect, useMemo } from "react"; import { useEffect, useMemo } from "react";
import { atom as $, useAtom, Atom, PrimitiveAtom, useAtomValue, useSetAtom, Provider } from 'jotai'; import { atom as $, useAtom, Atom, PrimitiveAtom, useAtomValue, useSetAtom, } from 'jotai';
type PickerInput = { type PickerInput = {
$options?:PrimitiveAtom<Array<string>>, $options?:PrimitiveAtom<Array<string>>,
@ -36,7 +36,6 @@ export function Picker({
},[url, isEnabled]) },[url, isEnabled])
return ( return (
<Provider>
<div> <div>
{isLoading {isLoading
? ?
@ -50,6 +49,5 @@ export function Picker({
</select> </select>
} }
</div> </div>
</Provider>
); );
} }
Loading…
Cancel
Save