Skip to content

Commit 0c1dfa9

Browse files
committed
Add elements interview questions
1 parent e2f1fce commit 0c1dfa9

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4345,12 +4345,26 @@
43454345
2. **Debouncing:** Publish changes after a period of inactivity. For example, it can be used using _.debounce lodash function
43464346
3. **RequestAnimationFrame throttling:** Changes based on requestAnimationFrame. For example, it can be used using raf-schd lodash function
43474347
261. ### How JSX prevents Injection Attacks?
4348-
By default, React DOM escapes any values embedded in JSX before rendering them. Thus it ensures that you can never inject anything that’s not explicitly written in your application. Everything is converted to a string before being rendered. For example, you can embed user input as below,
4348+
React DOM escapes any values embedded in JSX before rendering them. Thus it ensures that you can never inject anything that’s not explicitly written in your application. Everything is converted to a string before being rendered. For example, you can embed user input as below,
43494349
```javascript
43504350
const name = response.potentiallyMaliciousInput;
4351-
// This is safe:
43524351
const element = <h1>{name}</h1>;
43534352
```
43544353
This way you can prevent XSS(Cross-site-scripting) attacks in the application.
4354+
262. ### How to update rendered elements?
4355+
You can update UI(represented by rendered element) by passing the newly created element to ReactDOM's render method. For example, lets take a ticking clock example, where it updates the time by calling render method multiple times,
4356+
```javascript
4357+
function tick() {
4358+
const element = (
4359+
<div>
4360+
<h1>Hello, world!</h1>
4361+
<h2>It is {new Date().toLocaleTimeString()}.</h2>
4362+
</div>
4363+
);
4364+
ReactDOM.render(element, document.getElementById('root'));
4365+
}
43554366

4367+
setInterval(tick, 1000);
4368+
```
4369+
263. ###
43564370

0 commit comments

Comments
 (0)