A
A
ArrayPop2020-08-06 11:09:47
PHP
ArrayPop, 2020-08-06 11:09:47

How to pass variable from php file to react + typescript tsx file?

Here is the code written for example

<script>
window.list = 'aaaaaa'
</script>
<script src="build/react.js"></script>

And in the tsx file I'm already trying to use this variable. The problem is that typescript thinks that this variable does not exist, can I add it somehow? There, ts-linter most likely will not allow you to do this. Through ajax, I don’t want to send, once again make a request to the server, since there is not enough data there.
console.log(window.list)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2020-08-06
@ArrayPop

declare global {
    interface Window {
        list: string;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question