How can I make variables from 1 file present in another

app.js export async function main() { try { const accessToken = await getAccessToken(); const episodes = await getShowEpisodes(accessToken, showId); //get episodes names console.log('Show Episodes:', episodes); //name is a property in an array const episodeNames = episodes.map(obj => obj["name"]); console.log(episodeNames); return episodeNames; } catch (error) { console.error('An error occurred:', error.message); } } main() episodeList.astro --- import Layout from '../layouts/Layout.astro'; import Navbar from '../components/Navbar.astro'; import Card from '../components/Card.astro'; import {main} from '../utils/app.js' --- <Layout title="Episodes" > <div class="bg-slate-900"> <Navbar /> <h1 class="text-white">this is good</h1> <div class="text-white"> {main } </div> </div> <!-- <Card href='' title=${name} body='body of your mom' /> --> </Layout> <script> import '../utils/app.js' </script> How can i print the values of episodeName(app.js) in episodelist.astro I want episodelist.astro to be an index of episodes
17 Replies
JOY
JOYā€¢12mo ago
Senra
Senraā€¢12mo ago
use a map??
Rook
Rookā€¢12mo ago
I'm not really familiar with astro. What happens if you call main from within episodeList.astro at the top and store the result as a variable that gets used by the markup? Also yeah, you will probably have to map over it since it's an array
Senra
Senraā€¢12mo ago
I am pretty sure it just replaces the {main} place holder with the return value of main. So The return value must contain the markup for the list. Or at least that is what I think šŸ¤”
Rook
Rookā€¢12mo ago
Rook
Rookā€¢12mo ago
map over the return value to generate the markup within episodeList.astro
Senra
Senraā€¢12mo ago
Love how astro works similar to JSX
JOY
JOYā€¢12mo ago
the maps not working idk
Rook
Rookā€¢12mo ago
yeah, i'm gonna have to try it out 0.o would you post your code? kinda hard to help without that lol
JOY
JOYā€¢12mo ago
@rooook Check images for better view
Rook
Rookā€¢12mo ago
that doesn't contain any mapping in the astro file, i'm asking to see what you tried
JOY
JOYā€¢12mo ago
Ohh
Jochem
Jochemā€¢12mo ago
if you'd use the code blocks (```js and ```) instead of regular code with a single `, you'd get highlighting in Discord
console.log("This is much nicer for people trying to help");
console.log("This is much nicer for people trying to help");
JOY
JOYā€¢12mo ago
Thanks Didn't know
Jochem
Jochemā€¢12mo ago
make sure to read #How To Ask Good Questions, it has many more tips
JOY
JOYā€¢12mo ago
Map function not working(if the map is suitable function for it pls help me with the code). should i put all my app.js into top level episodeList.astro
Rook
Rookā€¢12mo ago
like i've said, it's hard to help without seeing what you've tried