javascript - Passing a value to bundled React JS file? -


i wonder if possible pass argument react entry point.

my entry point looks this:

module.exports = {     entry: "./js/components/application.js",     output: {         path: "./dist",         filename: "bundle.js"     },     // ... } 

my application.js:

import react 'react'; import reactdom 'react-dom'; import anothercomponent './anothercomponent';  reactdom.render(<anothercomponent />, document.getelementbyid('content')); 

not bundle application webpack , include bundle in application. application provides div id "content":

<body>     <div id="content"></div>     <script src="bundle.js" /> </body> 

i know can

<script src="bundle.js" myargument="somevalue" /> 

but how can value passing react component anothercomponent property?

what about

<script id="bundle" src="bundle.js" myargument="somevalue" /> 

and then

const myscript = document.getelementbyid('bundle');  reactdom.render(<anothercomponent     myargument = {myscript.getattribute('myargument')} />, document.getelementbyid('content')  ); 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -