tanhauhau/svelte-json-tree

Does it work with a promise? I have undefined.

davy-blavette opened this issue · 2 comments

Hi,

Maybe it doesn't work on a promise ?

<script>
    import { onMount } from "svelte";
    import {baseUrl} from "../data";
    import JSONTree from 'svelte-json-tree';

    let jsonTrainers;

    onMount(async () => {
        let res = await fetch(baseUrl);
        const trainer = res.json();
        trainer.then(function(result) {
            jsonTrainers = result[0].kolb.reponse;
            console.log(jsonTrainers);
        });

    });
</script>
<JSONTree {jsonTrainers} /> // <---- undefined

you need to pass the value in through the props named value

<JSONTree value={jsonTrainers} />

Thanks, perfect 👍