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

Did you find this page helpful?