Open AoDev opened 2 days ago
For the second case, it isn't part of the data cascade nor does it rely on anything in the 11ty configuration. You could just call it from the MainLayout
function, rather than counting on it to be injected, right?
It's a nice thing about this approach. It doesn't rely on some magical thing to get a callable into the "template" scope. It's just import it and call it.
For the former...11ty is going to hand a "layout" the same thing it a JavaScript Template function. So data
should have access to the data cascade.
Sorry for my ignorance here but I do not understand how I'd call an async function in MainLayout. It returns a JSX Element. It's not React where I could for example use useEffect to run an async operation that gets the data and re-renders. What am I missing?
11ty allows marking a JavaScript Template function as async
which then means you can do an await
on a line in the function.
Hi, nice project you did here! I am new to Eleventy and really wanted to start with typescript / tsx.
I didn't quite figure out how to use data in the tsx layouts. My final goal is to be able to run an async call and get data from somewhere.
I first tried with static data
global in _data folder,
like
_data/fruits.js
or_data/fruits.json
["apple", "pear"]And expected to be able to use it
But it's not injected.
end goal
Would be to have some async call somewhere. For example:
And be able to use it in