This question already has answers here:
React Native property values in quotes vs braces
(1 answer)
What do curly braces mean in JSX (React)?
(4 answers)
Closed 8 months ago.
<button className='btn' onClick={() => setValue(value - 1)}>
<form className='form' onSubmit={handleSubmit}>
I hope I don't get people riled up asking this. I tried to google and cannot find the answer. Why for some attributes in HTML uses 'xxx', eg classname='btn' and why some attributes uses {}, eg onSubmit={xxx}.
In the above case, the handleSubmit is a externally define function. Does {} imply a variable, that's all ? But I also saw some codes similar to this onSubmit={() => xxxx} which is an inline function and not an external variable.
Currently, I just memorise it as it come. Thanks very much !
Related
This question already has answers here:
Are 'Arrow Functions' and 'Functions' equivalent / interchangeable?
(4 answers)
Closed 2 years ago.
I never understood how that this works if it ever works
in my react I wrote <input onChange={()=>console.log(this.value)} /> Why doesn't it recognize this??? it tells me that it Cannot read property 'value' of undefined
onChange anyone help please :/
React doesn't bind the event listener with the element.
So, the this refers to the class Component in which its defined.
If it was in functional Component then this it undefined
So if your trying to read input elements value use this,
<input onChange={e => console.log(e.target.value)} />
Read More,
Function And Class Components
This question already has answers here:
C++ global initialization order ignores dependencies?
(7 answers)
static initialization order fiasco
(4 answers)
Closed 3 years ago.
I'm developing a webserver using C++ and I want a string array to contain the HTML code of my HTML elements.
In the definition of that array, I want to supplement hard-coded characters with strings that are defined in other arrays.
For example, my webpages[] array would contain the HTML for each webpage and be defined as:
string webpages[NUM_WEBPAGES] =
{
...
"<p>Please login here</p>",
...
};
However, the HTML that gets sent to the client is:
<p>Please login here</p>
As you can see, the url from urls[PAGE_LOGIN] was not populated into the HTML.
I have confirmed via code inspection and gdb that urls[PAGE_LOGIN] has the value /login.
(1) Why is this not working?
(2) Is this possible?
(3) If no, any recommendations?
Thank you!
EDIT:
Minimal reproducible code example... because I don't know how to stackoverflow.
Also my C++ is bad.
webpages.h:
enum webpage
{
PAGE_LOGIN,
NUM_WEBPAGES
};
extern string webpages[NUM_WEBPAGES];
webpages.cpp:
string webpages =
{
"<p>Please login here</p>",
};
urls.h:
extern string urls[NUM_WEBPAGES];
urls.cpp:
string urls[NUM_WEBPAGES] =
{
"/login"
};
This question already has answers here:
Button that refreshes the page on click
(18 answers)
Closed 3 years ago.
I want to refresh my website after clicking on a specific area (container)
Any ideas?
THANKS!
You can use Location.reload() API interface (https://developer.mozilla.org/ru/docs/Web/API/Location/reload)
So the answer could look as follows:
document.querySelector('you-area-selector-here').addEventListener((click) => {
window.location.reload(true);
})
true flag is required to be sure the page was reloaded from server, not from cache.
It is not a good practice to mix js with HTML.
I would do it this way:
let refreshPage = document.querySelector('#div1').addEventListener('click', => {
location.reload();
})
note: you must give id or class to the element you are trying to select in this function.
There are other way of doing it i.e = document.querySelectorAll, getElementById, getElementByClassName, getElementByTagName.
This question already has answers here:
How to call native es6 template string replacement from tag function?
(4 answers)
Closed 5 years ago.
With ES6 we can create "tag functions" which operate on a template string.
Is it possible to call the "default" tag function from within another one (that is, the one that is used when there is no prefix before the backtick
e.g.
function html(template, ...substitutions)
{
substitutions= substitutions.map(s=>SafelyEscapeStringForHtml(s));
return DefaultTagFunction(template, ...substitutions);
}
the upshot of which is that my tag function doesn't need to deal with the concatenation and ensuring the parameters are inserted into the correct locations in the template. (Sure this isn't hard, but it's ugly and I don't want to see it in every tag function!)
Your own answer came close - you can abuse String.raw to give you what you want (with interpreted escape sequences):
function html(template, ...substitutions)
{
substitutions= substitutions.map(s=>SafelyEscapeStringForHtml(s));
return String.raw({ raw: template }, ...substitutions);
}
This is essentially just tricking it into thinking that the escape-interpreted string is the raw version.
String.raw() is the default tag function
So the above code can be written as
function html(template, ...substitutions)
{
substitutions= substitutions.map(s=>SafelyEscapeStringForHtml(s));
return String.raw(template, ...substitutions);
}
This question already has answers here:
Selecting attribute values with html Agility Pack
(7 answers)
Closed 8 years ago.
I want to get the href-link from this:
<a class="abc" href="/subsite/2014/05/19/site.html"> <p>test1</p><p>test2</p> </a>
I'm trying this:
var nodes = doc.DocumentNode.SelectNodes("//a[#class='abc']/#href");
...InnerHtml becomes <p>test1</p><p>test2</p>, not the link in the href...
As explained by HtmlAgilityPack creator, #SimonMourier, here, you can't use SelectNodes() directly to get attributes (as the method name and the return type implies, it meant to select nodes).
You need to do it with different approach. Try to select the node instead of the attribute, then you can use LINQ extension method to extract attribute of each selected nodes, for example :
var attrs = doc.DocumentNode
.SelectNodes("//a[#class='abc' and #href]")
.Select(o => o.Attributes["href"]);
This will work too, as described in the link from #Tomalak.
//Load navigator for current document
HtmlNodeNavigator navigator = (HtmlNodeNavigator)doc.CreateNavigator();
//Get value from given xpath
string xpath = "//a[#class='abc']/#href";
var val = navigator.Select(xpath);