facebook / create-react-app

Set up a modern web app by running one command.
https://create-react-app.dev
MIT License
102.56k stars 26.79k forks source link

Development Server not refreshing -react-app #9756

Open Risingabhi opened 3 years ago

Risingabhi commented 3 years ago

Issue: Despite restarting server many times with npm start, same old error is showing up. ./src/components/slider.js Line 9:25: Parsing error: Unexpected token

7 | 8 |

9 | <h2 class = "w3-center" | ^ 10 | <div class ="w3-content w3-section" style = {{max-width : "500px"}}> 11 | <img class = "mySlides" src = "./images/banner1.png" style ={{width:"100%"}}> 12 | <img class = "mySlides" src = "./images/banner2.jpg" style ={{width:"100%"}}>

--------------------------------------------------------------------(The Actual code edited is below)............................... import React,{Component} from 'react';

class Monty extends React.Component { render(){ return(

Automatic

<script>

var myIndex = 0; carousel(); kk function carousel() { var i; var x = document.getElementsByClassName("mySlides"); for (i = 0; i < x.length; i++) { x[i].style.display = "none";
} myIndex++; if (myIndex > x.length) {myIndex = 1}
x[myIndex-1].style.display = "block";
setTimeout(carousel, 2000); // Change image every 2 seconds }

}
}
);
export default Monty;

What is troubling me is despite closing the server and refreshing it , same error is showing up.

Already tried following Solutions: 1- Adding REACT_EDITOR=atom ( including .env file ) 2- Closing the server and restarting it, 3- Deleting all history from Browser chrome .

I am new to React, so not sure why this error is happening and how i can rectify the same.

Addtional Information: App.js import React from 'react'; import MyForm from './components/form'; import Imagine from './components/test'; import {Button, Badge} from 'react-bootstrap'; import 'bootstrap/dist/css/bootstrap.min.css'; import Monty from './components/slider';

function App() {

return (

F L I R T

Best Offers
)
};

export default App;

eddiemonge commented 3 years ago

Wrap your code in Github in triple tildes ``` to create code blocks.

Why are you returning scripts in the JSX? Its not working probably because there are errors parsing it

ManoharSomu commented 3 years ago

Do you want to fetch and execute the script, again and again, every time this component is rendered, or just once when this component is mounted into the DOM

ManoharSomu commented 3 years ago

Use template literals inside styles

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.