How to use React/JSX to wait for React to load before styles are loaded?
P粉106301763
P粉106301763 2023-09-01 00:24:34
0
1
386

I keep having this problem when using js/jsx/react, my logic is running before the page loads and therefore, I keep getting errors as to what is not my code Trying to execute before the page has finished loading, causing a lot of errors.

How do I consistently prevent this/protect myself from these problems?

I've tried using a bunch of window.onload() functions, but that just doesn't feel right and I feel like there should be a better way to do this, which I can't find by googling or on the form.< !-- p-->

// an example of my issue is the following code consistently errors: function Title() { var text = "Hello"; var arr = []; //convert word into an array of chars for (let i=0; i<=text.length; i ){ console.log("loop") arr.push(text.charAt(i)); } //output each letter into a span const listItems = arr.map((number) => {number}); //neither of these works // document.getElementById('title').style.color = ('rgba(0, 0, 0, 0.0)'); // document.getElementById('title').style.color = "#ffFFff" return ( 

{listItems}

) }

A bug I often get is that react claims that the jsx declared style I'm trying to change/access "doesn't exist", but if I try to change it in the browser's console it works fine.

P粉106301763
P粉106301763

reply all (1)
P粉073857911

To add inline styles to React elements, you should use the style attribute. so:

{listItems}

You cannot access DOM elements rendered on the component body, you should use ref anduseEffectfor this purpose.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!