Похожие чаты

If I pass data using data-* attribute in script tag

then can I access this data in my package which is react app? If it is simple javascript file then I can access but in react app is it possible?

13 ответов

25 просмотров

It's still just JavaScript, anything's possible; but you may be doing something weird. This is an XY question. Tell us what you want to do instead of how.

Adi- Автор вопроса
MUTHU・KUMAR 「メーカー」 🔺
It's still just JavaScript, anything's possible; b...

I am creating react widget in which I am loading my widget on website using CDN script tag. Now this widget is react app. I want to pass token using data-* attribute to react app how can I do that ? script tag code: <script src="https://unpkg.com/mypackage@1.0.1/index.js" data-token="100200"></script> now how to access this token attribute in react app? I am using webpack with react app so I am generating single bundle.js file. Let me know if you need some more info I think this is sufficient

Adi
I am creating react widget in which I am loading m...

If it'll be a single bundle you can do document.currentScript.dataset.token

Adi- Автор вопроса
MUTHU・KUMAR 「メーカー」 🔺
If it'll be a single bundle you can do document.c...

But in which file of my react app? Can I access it in app.js file?? Which file can access this token!?

Adi
But in which file of my react app? Can I access it...

Anywhere should work, saving it in a variable at top level would be best

Adi- Автор вопроса
MUTHU・KUMAR 「メーカー」 🔺
Anywhere should work, saving it in a variable at t...

Anywhere should work?? But could not understand how anywhere should work?? I was thinking it will be available only in app.js

Adi- Автор вопроса
MUTHU・KUMAR 「メーカー」 🔺
It is bundled into a single script, yes?

Yes i am using webpack and it will generate single bundle.js file in dist folder

Adi- Автор вопроса
Adi
Oh ok got it. Let me try it out. Thanks for helpin...

Just be sure to not use it from an event handler; since the element that triggers the event will be the target then. So in case you need to use it inside an event handler, assign it to a variable at the top level and pass it down

Adi- Автор вопроса
MUTHU・KUMAR 「メーカー」 🔺
Just be sure to not use it from an event handler; ...

No in my case I am passing token as data attribute into my react app using CDN script tag and then once token is available in app.js I will display different components based on different tokens in react widget thats the plan. Anything you would like to suggest or looks good?

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта