DataBinding Flashcards

This deck contains the cards for ReactJS two binding details

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

A
22
Q

Behavior Patterns

A
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
Q

What is a onclick event ?

A
26
Q

What is an Event Handler ?

A

Events are configured for elements using an EventListener or EventHandler
React uses EventHandler for Synthetic events
Syntax:
<button onClick={insertClick}>
onClick={insertClick} => EventHandler
onClick => Event

onChange : ChangeEventHandler : EventHandler
onClick : ClickEventHandler : EventHandler

27
Q

How many ways event handler can be configured

A

1) Inline Functionality
Syntax: <button onClick={function(){alert(‘insert clicked’);}}>Insert</button>
<button onClick={() => {alert(‘insert clicked’);}}>Insert</button>
2) Embedded Functionality
Syntax:
function InsertClick(){}
<button onClick={InsertClick}>Insert</button>

28
Q

What is the advantage of Embedded Event Handler ?

A

it can be used across various requests

29
Q

What are Event arguments ?

A

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
Q

What is event propagation ?

A

Child event is propagated to the parent event. Stop propagation can prevent it.

31
Q

What is prevent default ?

A

HTML form provides generic buttons (Predefined functionality)
a) Submit <button> Submit form data to server
b) Reset <button> - Reset form data
<button> - default is submit
HTML form provides non-generic buttons ( without Predefined functionality)
<button></button></button></button></button>

Generic elements have predefined functionality which firesup after the custom functions that you defined for an element

32
Q

Can we have multiple forms in a component ?

A

Yes

33
Q

Can we configure a form within another form (nested forms) ?

A

No. Possible with Pusedo froms

<form>
<div form="></div>
</form>

34
Q

AJAX

A

used for partial post forms

35
Q

Can we have multiple submit buttons ?

A

Yes

36
Q

DOM Hierarchy

A
37
Q

Form Submit

A
38
Q

How to handle onload action in react ?

A

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
Q

Various Synthetic Events in React

A
  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
Q

When to use KeyUp, KeyDown, KeyPress ?

A

KeyPress - Use it for ASCII chars
KeyUp, KeyDown - Use it for chars

41
Q

Element State Events

A
  • onBlur
  • onFocus
  • onChange
  • onSelectStart
42
Q

Double Click Event

A
43
Q

Disable Right Click

A

Actual DOM, virtual DOM deals with component only. Synthetic events work only for components.

44
Q

ClipBoard Events

A

onCut
onCopy
onPaste

45
Q

Touch Events

A

onTouchStart
onTouchEnd
onTouchMove

46
Q

Timer Events

A

setTimeout()
clearTimeout()
setInterval()
clearInterval()

47
Q

setTimeout()

A
48
Q

clearTimeout()

A
49
Q

setInterval()

A
50
Q

Form Events

A
  1. These events will fireup only with generic buttons(submit, reset)
    Syntax : <form onSubmit={handleSubmit} onReset={handleReset}>
    <button>Submit</button>
    <button>Cancel</button>

</form>
2.