background image
James DiGioia

my little web home

Top-Level Modules

import React from 'react';
import { getWidgets, createWidget } from '../widget';

export const WidgetView = ({ widgets }) => {
  const [widgets, setWidgets] = useState([]);
  
  useEffect(() => {
    getWidgets()
      .then(widgets => setWidgets(widgets));
  }, []);
  
  const onButtonClick = async () => {
    await createWidget();
    const widgets = await getWidgets();
    setWidget(widget);
  };

  return (
    <>
      <ul>
        {widgets.map(widget => (
          <li key={widget.id}>{widget.name}</li>
        ))}
      </ul>  
      <button onClick={onButtonClick}>Add widget</button>
    </>  
  );
}
// src/widget/index.js
export { Widget } from './Widget.js';
export { getWidgets, createWidget, updateWidget, deleteWidget } from './api.js';
export { encoder, decoder } from './schema.js';