recentpopularlog in

therobyouknow : element   32

reactjs - React—add a click listener to dangerouslySetInnerHTML sub-element - Stack Overflow
class Element extends React.Component {
state = {
loadTime: 0,
lastUpdate: 0
};

lastUpdateTimer = null;

componentDidMount() {
this.resetTimer();

this.lastUpdateTimer = setInterval(this.setLastUpdate, 1000);

this.dynamicContentElement.addEventListener("click", this.handleClick)
}

componentWillUnmount() {
clearInterval(this.lastUpdateTimer);
this.dynamicContentElement.removeEventListener(this.handleClick)
}

resetTimer() {
const now = Date.now();

this.setState({
loadTime: now,
lastUpdate: now
});
}

setLastUpdate = () => {
this.setState({
lastUpdate: Date.now()
});
}

getDynamicContent() {
const time = Math.round((this.state.lastUpdate - this.state.loadTime) / 1000);
return {
__html: `<p>
You are here: <strong>${time}</strong> seconods.
<br>
<button id="btn">Click to reset counter</button>
</p>`
};
}

handleClick = (e) => {
if (e.target.id === "btn") {
this.resetTimer();
}
}

render() {
return (
<div>
Dynamic content below:
<div
ref={el => this.dynamicContentElement = el}
dangerouslySetInnerHTML={this.getDynamicContent()}
/>
</div>
);
}
}
reactjs  react  js  javascript  computing  listener  click  onclick  element  subelement  sub  howto  web  dev  event  events 
april 2019 by therobyouknow
Method 2. Passing Individual Items to PayPal
form field elements definitive guide. note that quantity_n is not mentioned (e.g. quantity_1 for quantity of item 1 quantity_2 for quantity of item 2) but works!
form  element  field  multiple  multi  paypal  payment  ecommerce  html  markup  official  definitive  computing  reference 
june 2013 by therobyouknow
Print an array one element per line, with line numbering - Perl Circus - Perl Tricks, Tips And Traps.
in a foreach (@array), $_ *refers* to the element being looked at in an iteration. writing to $_ modifies the element in the original array - update in-place. This enables efficiency if passing the array around for stages of processing, rather than working with copies - and also ensures that the original data is updated (if that's what is required)
programming  tutorial  perl  inspiration  array  $_  in-place  inplace  update  within  loop  foreach  reference  efficiency  efficient  howto  computing  work  language  tip  iterate  alias  element  modify  original 
september 2009 by therobyouknow

Copy this bookmark:





to read