const location = 'abc';
const template = <p>Location: {location}</p>;
ReactDOM.render(template, document.getElementById('app'));
The above code keeps redirecting my page to '/abc'.
Babel compiles the above code to:
'use strict';
var location = 'abc';
var template = React.createElement(
'p',
null,
location
);
var appRoot = document.getElementById('app');
ReactDOM.render(template, appRoot);
I suspect that the "location" variable name is reserved for React, but am not sure why this keeps happening. Can anybody explain what the problem is? Am I not supposed to use 'location' as a variable name when using React?
Not specific to React, but just a collision with the global location
object, that provides access to the current URL.
The
Window.location
read-only property returns aLocation
object with information about the current location of the document.Though Window.location is a read-only Location object, you can also assign a DOMString to it. This means that you can work with location as if it were a string in most cases:
location = 'http://www.example.com'
is a synonym oflocation.href = 'http://www.example.com'
.
I am developing an Quiz Application in MVC 5. I have added two tables in database. One for marks and other for Questions and Answers. I have entered data in database for question, answers and have ...
I am developing an Quiz Application in MVC 5. I have added two tables in database. One for marks and other for Questions and Answers. I have entered data in database for question, answers and have ...
I have an array such as [2,5,3,1] each number represents an index number. How would I be able to construct an object path using these nodes? For example: [2,5] would create: myObject.conversations[i]...
I have an array such as [2,5,3,1] each number represents an index number. How would I be able to construct an object path using these nodes? For example: [2,5] would create: myObject.conversations[i]...
I have two video sources that are outputted to my page via ajax (the second is hidden). I play the first one and bind an event onto it so that when it has ended the next video is played and shown ...
I have two video sources that are outputted to my page via ajax (the second is hidden). I play the first one and bind an event onto it so that when it has ended the next video is played and shown ...
I have an array with this loop: var arr = [5, 4, 9, 6, 4]; var sum = 0; arr.forEach(function(item) { sum += parseInt(item); console.log(sum) }); At the moment, I get ...
I have an array with this loop: var arr = [5, 4, 9, 6, 4]; var sum = 0; arr.forEach(function(item) { sum += parseInt(item); console.log(sum) }); At the moment, I get ...