20
loading...
This website collects cookies to deliver better user experience
import { Fragment } from 'preact';
import { useState } from 'preact/hooks';
import '@apollo-elements/components/apollo-client';
import '@apollo-elements-demos/spacex-launches';
export const LaunchesDemo = ({ limit = 10 }) => {
const [{ missionName, id }, setSelectedLaunch] = useState({});
const [launches, setLaunches] = useState([]);
return (
<Fragment>
<apollo-client uri="https://api.spacex.land/graphql">
<spacex-launches
limit={limit}
onselected-launch-changed={({ detail }) => setSelectedLaunch(detail)}
onlaunches-changed={({ detail }) => setLaunches(detail)}
></spacex-launches>
<p>From {launches.length} launches, you selected {missionName || 'nothing'}.</p>
</apollo-client>
</Fragment>
);
};
import React, { createRef, useState, useEffect } from "react";
import '@apollo-elements/components/apollo-client';
import "@apollo-elements-demos/spacex-launches";
export const LaunchesDemo = ({ limit }) => {
const launchesRef = createRef(null);
const launchRef = createRef(null);
const [{ missionName, id }, setSelectedLaunch] = useState({});
const [launches, setLaunches] = useState([]);
useEffect(() => {
launchesRef.current.addEventListener("launches-changed", ({ detail }) => setLaunches(detail));
launchesRef.current.addEventListener("selected-launch-changed", ({ detail }) => setSelectedLaunch(detail));
}, [launchesRef.current]);
useEffect(() => {
launchesRef.current.limit = limit;
}, [limit]);
return (
<React.Fragment>
<apollo-client uri="https://api.spacex.land/graphql">
<spacex-launches ref={launchesRef}></spacex-launches>
<p>From {launches.length} launches, you selected {missionName || "nothing"}.</p>
</apollo-client>
</React.Fragment>
);
};
<table>
layouts and image maps, still happily running three decades hence.