DataBinding Flashcards

This deck contains the cards for ReactJS two binding details (50 cards)

1
Q

Is two way databinding supported with ReactJS ?

A

Implicitly it is not supported

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is two way binding ?

A

Access data from source and binding to the UI.
Update UI changes back to source.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Two way binding example ?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Drawback of React ?

A

Supports only one-way binding

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Code Example

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Event for 2 way binding

A

OnChange only

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Default JS event args

A

this(info about object) and event (event details)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

React Event arg

A

React can use only one arg, which provides access to both object and event details.
event (object and event related details ) (this is used in JS)
event.target.id, name, value, calssName
event.clientX, clientY, shitKey, ctrlKey

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

React and Java Script two way binding differences ?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Code Example

A

// FlashCard.js
import React from ‘react’;

class FlashCard extends React.Component {
handleChange = (event) => {
// Call the parent’s onChange method with the updated value
this.props.onChange(event.target.value);
};

render() {
return (
<div>
<label>{this.props.label}</label>
<input
type=”text”
value={this.props.value}
onChange={this.handleChange}
/>
</div>
);
}
}

export default FlashCard;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

JS and React Examples

A

<input></input>

<p></p>

<script>
const inputElement = document.getElementById('myInput');
  const outputElement = document.getElementById('output');

  inputElement.addEventListener('input', function(event) {
    outputElement.textContent = event.target.value;
  });
</script>

import React, { useState } from ‘react’;

function MyComponent() {
const [inputValue, setInputValue] = useState(‘’);

return (
<div>
<input
type=”text”
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
/>
<p>{inputValue}</p>
</div>
);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Different types of Binding

A

Data Binding (one way, two way)
Style Binding
Class Binding
Event Binding

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Style Binding

A

Apply styles dynamically to any element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

JavaScript Style Binding

A

<input></input>
document.getElementById(“userName”).style.cssAttribute=”value”
CSS => background-color => backGroundColor
=> font-style => fontStyle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

React Style Binding

A

<input type=”text” style={{attributeName:value,attributeName:value}} /> (value must be string, style attributes are javascript objects)

<input></input> => Invalid
<input type=”text” style={{color:’red’}} => valid (inline Styles)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Code Example

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Html style types

A

1) inline (faster, not reusable)
2) embedded (not reusable)
3) external (reusable)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is difference between display:none and visibility:hidden

A

display:none hides and allocated space is removed
visibility:hidden allocated space is retained

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Issues with StyleBinding

A

Style is inline and it is good with individual elements, not reusable across elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Event Binding in React

A

Event is a message sent by a sender to its subscriber in order to notify the change.
Design Pattern - “Observer” . it is under “Behavioral Patterns”
Event uses “Delegate” mechanism[Function Pointer]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Structural Pattern

22
Q

Behavior Patterns

23
Q

what is an event ?

A

Every event is a browser event
in JS html elements can use the browser events
React cant use “browser” events [Browser events are related BOM]
React uses a virtual DOM library called “SyntheticEvents” , which map to browser events.

24
Q

Actual and Synthetic events

A

ReactJS is builtin with typescript
Every event extends “SyntheticEvent” [interface]

25
What is a onclick event ?
26
What is an Event Handler ?
Events are configured for elements using an EventListener or EventHandler React uses EventHandler for Synthetic events Syntax:
27
How many ways event handler can be configured
1) Inline Functionality Syntax: 2) Embedded Functionality Syntax: function InsertClick(){}
28
What is the advantage of Embedded Event Handler ?
it can be used across various requests
29
What are Event arguments ?
Every event in React have a default argument, which maps to "Event" base Event base can provide access to both element related properties and event properties. Event properties are accessible using "target" e.target.value, e.target.Id Event properties are accessible directly e.clientX, e.clientY, e.shiftKey, e.which, e.ctrlKey
30
What is event propagation ?
Child event is propagated to the parent event. Stop propagation can prevent it.
31
What is prevent default ?
HTML form provides generic buttons (Predefined functionality) a) Submit
32
Can we have multiple forms in a component ?
Yes
33
Can we configure a form within another form (nested forms) ?
No. Possible with Pusedo froms
34
AJAX
used for partial post forms
35
Can we have multiple submit buttons ?
Yes
36
DOM Hierarchy
37
Form Submit
38
How to handle onload action in react ?
React does not have load event for component. It has "Mount" event. "Mount" event is defined for handling actions when the component is mounted onto page. Function component mount event is defined by using a Hook called "useEffect" useEffect(() => {},[dependencies]); useEffect(() => { setUserName('John'); ),[]);
39
Various Synthetic Events in React
1. Syntetic Mouce Events * onMouseOver * onMosueOut * onMouseUp * onMouseDown * onMouseMove 2. Synthetic Keyboard Events * onKeyUp * onKeyDown * onKeyPress Used with KeyEvent Properties - KeyCode, charCode,whick, shiftKey,CtrlKey, altKey
40
When to use KeyUp, KeyDown, KeyPress ?
KeyPress - Use it for ASCII chars KeyUp, KeyDown - Use it for chars
41
Element State Events
* onBlur * onFocus * onChange * onSelectStart
42
Double Click Event
43
Disable Right Click
Actual DOM, virtual DOM deals with component only. Synthetic events work only for components.
44
ClipBoard Events
onCut onCopy onPaste
45
Touch Events
onTouchStart onTouchEnd onTouchMove
46
Timer Events
setTimeout() clearTimeout() setInterval() clearInterval()
47
setTimeout()
48
clearTimeout()
49
setInterval()
50
Form Events
1. These events will fireup only with generic buttons(submit, reset) Syntax : 2.