FullStackCafe QAS 1634911205373
FullStackCafe QAS 1634911205373
FullStackCafe QAS 1634911205373
Q1: When rendering a list what is a key and what is it's purpose?
☆☆
Topics: React
Answer:
Keys help React identify which items have changed, are added, or are removed. Keys should be given to the
elements inside the array to give the elements a stable identity. The best way to pick a key is to use a string that
uniquely identifies a list item among its siblings.
render () {
return (
<ul>
{this.state.todoItems.map(({task, uid}) => {
return <li key={uid}>{task}</li>
})}
</ul>
)
}
Most often you would use IDs from your data as keys. When you don't have stable IDs for rendered items, you
may use the item index as a key as a last resort. It is not recommend to use indexes for keys if the items can
reorder, as that would be slow.
Topics: React
Answer:
For example, AngularJS (1.x) approaches building an application by extending HTML markup and injecting various
constructs (e.g. Directives, Controllers, Services) at runtime. As a result, AngularJS is very opinionated about the
greater architecture of your application — these abstractions are certainly useful in some cases, but they come
at the cost of flexibility.
By contrast, React focuses exclusively on the creation of components, and has few (if any) opinions about an
application’s architecture. This allows a developer an incredible amount of flexibility in choosing the architecture
they deem “best” — though it also places the responsibility of choosing (or building) those parts on the
developer.
Topics: React
Answer:
At the highest level, React components have lifecycle events that fall into three general categories:
1. Initialization
Page 1 of 8
FullStack.Cafe - Kill Your Tech Interview
2. State/Property Updates
3. Destruction
Topics: React
Answer:
Topics: React
Answer:
The state property is updated in a React component with the object passed into setState , and this is done
asynchronously. It tells React that this component and its children need to be re-rendered, but React may not do
this immediately (it may batch these state update requests for better performance).
Topics: React
Answer:
Unidrectional application flow paradigm popular a few years back in React; mostly superceded by Redux these
days.
Topics: React
Answer:
Page 2 of 8
FullStack.Cafe - Kill Your Tech Interview
JSX is a syntax notation for JavaScript XML(XML-like syntax extension to ECMAScript). It stands for JavaScript
XML. It provides expressiveness of JavaScript along with HTML like template syntax. For example, the below text
inside h1 tag return as javascript function to the render function,
render(){
return(
<div>
<h1> Welcome to React world!!</h1>
</div>
);
}
Topics: React
Answer:
1. Functional components: This is the simplest way to create ReactJS components. It accepts props as an
Object and returns ReactJS elements. We call it as “functional” because those are pure JavaScript functions.
function Greeting(props) {
return <h1> Hello, {props.message}</h1>
}
2. Class components: You can also use Es6 class to define component. The above functional component can
be written as below,
Topics: React
Answer:
Both props and state are plain JavaScript objects. While both of them hold information that influences the
output of render, they are different in their functionality with respect to component. i.e,
Topics: React
Page 3 of 8
FullStack.Cafe - Kill Your Tech Interview
Answer:
The callback function is invoked when setState finished and the component gets rendered. Since setState is
asynchronous the callback function is used for any post action.
setState({name: 'sudheer'}, () => console.log('The name has updated and component re-rendered'));
Topics: React
Answer:
You can use an arrow function to wrap around an event handler and pass parameters:
Topics: React
Answer:
Refs are created using React.createRef() method and attached to React elements via the ref attribute. In order
to use refs throughout the component, just assign the ref to the instance property with in constructor.
And:
Page 4 of 8
FullStack.Cafe - Kill Your Tech Interview
type='text'
ref={(input) => this.input = input} /> // Access DOM input in handle submit
<button type='submit'>Submit</button>
</form>
)
}
}
Topics: React
Answer:
It's common pattern in React which is used for a component to return multiple elements. Fragments let you
group a list of children without adding extra nodes to the DOM.
render() {
return (
<React.Fragment>
<ChildA />
<ChildB />
<ChildC />
</React.Fragment>
);
}
render() {
return (
<>
<ChildA />
<ChildB />
<ChildC />
</>
);
}
Topics: React
Answer:
Portals provide a first-class way to render children into a DOM node that exists outside the DOM hierarchy of the
parent component.
Sometimes it’s useful to insert a child into a different location in the DOM:
render() {
// React does *not* create a new div. It renders the children into `domNode`.
// `domNode` is any valid DOM node, regardless of its location in the DOM.
return ReactDOM.createPortal(
this.props.children,
Page 5 of 8
FullStack.Cafe - Kill Your Tech Interview
domNode );
}
A typical use case for portals is when a parent component has an overflow: hidden or z-index style, but you
need the child to visually “break out” of its container.
Topics: React
Answer:
If the behaviour is independent of its state then it can be a stateless component. You can use either a function
or a class for creating stateless components. But unless you need to use a lifecycle hook in your components,
you should go for stateless functional components.
Stateful/Container/Smart component:
Stateless/Presentational/Dumb component:
There are a lot of benefits if you decide to use stateless functional components here; they are:
Topics: React
Answer:
If the behaviour of a component is dependent on the state of the component then it can be termed as stateful
component. These Stateful components are always class components and have a state that gets initialized in the
constructor.
Page 6 of 8
FullStack.Cafe - Kill Your Tech Interview
render() {
// omitted for brevity
}
}
Topics: React
Answer:
Topics: React
Answer:
Flow is a static type checker, designed to find type errors in JavaScript programs, created by Facebook. Flow
types can express much more fine-grained distinctions than traditional type systems. For example, Flow helps
you catch errors involving null, unlike most type systems.
Answer:
ReactJS is a JavaScript library, supporting both front end web and being run on the server, for building user
interfaces and web applications.
React Native is a mobile framework that compiles to native app components, allowing you to build native
mobile applications (iOS, Android, and Windows) in JavaScript that allows you to use ReactJS to build your
components, and implements ReactJS under the hood.
Topics: React
Problem:
Page 7 of 8
FullStack.Cafe - Kill Your Tech Interview
...
const [count, setCounter] = useState(0);
const [moreStuff, setMoreStuff] = useState(...);
...
Solution:
useState is one of build-in react hooks. useState(0) returns a tuple where the first parameter count is the
current state of the counter and setCounter is the method that will allow us to update the counter's state.
We can use the setCounter method to update the state of count anywhere - In this case we are using it inside of
the setCount function where we can do more things; the idea with hooks is that we are able to keep our code
more functional and avoid class based components if not desired/needed.
Page 8 of 8