#How to pass data down to children from a component

3 messages · Page 1 of 1 (latest)

sonic mango
#

I need a lot of help. I'm working on a library that allows you to format data like this:

export default function Page() {
    return (
        <Collection
            path="/posts"
            where={["content", "==", "test"]}
            render={(data) => (
                <div className="bg-zinc-100 rounded-lg p-4">
                    <pre className="font-medium">
                        {JSON.stringify(data, null, 2)}
                    </pre>
                </div>
            )}
        />
    );
}
export const Collection: React.FC<CollectionProps> = ({
    path,
    where,
    render,
    loadingSlot,
}) => {
    const { db } = useGlobalFirebase();

    if (db === null) {
        console.error("Firebase db context not found");
        return null;
    }

    const [data, loading] = useCollection<DocumentData[]>(db, path, where);

    if (loading) {
        return <>{loadingSlot || <div>Loading...</div>}</>;
    }

    if (!data) {
        return <div>No data found</div>;
    }

    return <>{render(data)}</>;
};

This works just fine in React, but when I go to Next with it, it breaks.

  <... path="/posts" where={[...]} render={function render}>
                                          ^^^^^^^^^^^^^^^^^```

I've tried everything and I don't know if this is even possible to have it work like this. Please help, lmfao
umbral thicketBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

shut shuttle