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
JOYOP•17mo ago
Senra
Senra•17mo ago
use a map??
Rook
Rook•17mo 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•17mo 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•17mo ago
Rook
Rook•17mo ago
map over the return value to generate the markup within episodeList.astro
Senra
Senra•17mo ago
Love how astro works similar to JSX
JOY
JOYOP•17mo ago
the maps not working idk
Rook
Rook•17mo 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
JOYOP•17mo ago
@rooook Check images for better view
Rook
Rook•17mo ago
that doesn't contain any mapping in the astro file, i'm asking to see what you tried
JOY
JOYOP•17mo ago
Ohh
Jochem
Jochem•17mo 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
JOYOP•17mo ago
Thanks Didn't know
Jochem
Jochem•17mo ago
make sure to read #How To Ask Good Questions, it has many more tips
JOY
JOYOP•17mo 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•17mo ago
like i've said, it's hard to help without seeing what you've tried
Want results from more Discord servers?
Add your server