Rahul Vijayan
Follow for more updates
TCS Wings 1 T1 MERN - Set 1
- James is working on a React application. He notices that after a certain update, the state isn't updating as expected when using the
useState
hook. Which of the following is the most likely cause?- a) James is not updating the state directly in the component function.
- b) James is mutating the state directly instead of using the setter function returned by
useState
. - c) James is using
useEffect
to trigger the state update. - d) James is using multiple
useState
hooks, which are overwriting each other.
useState
.
- Lily is implementing a function in her React component to fetch data from an API. She wants this to happen only once when the component mounts. Which lifecycle hook should she use to achieve this?
- a)
componentDidUpdate
- b)
useEffect
with an empty dependency array - c)
useState
- d)
componentWillUnmount
useEffect
with an empty dependency array - a)
Sam is building a login form in React and is using
Axios
to call a REST API endpoint. He’s noticing that the request is sent twice every time he submits the form. What might be the reason?- a) Sam is using the
useEffect
hook incorrectly, causing it to rerun. - b) Sam has accidentally called the function twice in the button’s
onClick
handler. - c) Sam’s form is submitting both via
onClick
and the form’ssubmit
event. - d) Sam is not using
Axios
correctly.
Answer: c) Sam’s form is submitting both via
onClick
and the form’ssubmit
event.- a) Sam is using the
- Maya wants to add a feature where her Express app logs each incoming request. Which middleware function should she use to achieve this?
- a) Error-handling middleware
- b) Route-level middleware
- c) Application-level middleware
- d)
next()
middleware
Adam is working with MongoDB and needs to retrieve documents sorted by a specific field. Which method will help him achieve this?
- a)
sort
- b)
aggregate
- c)
find
- d)
filter
Answer: a)
sort
- a)
- Priya needs to display a list of items in her React app with sorting and filtering options. Which hook would be most useful to update the UI when sorting criteria change?
- a)
useRef
- b)
useEffect
- c)
useMemo
- d)
useCallback
useEffect
- a)
- Ethan wants to optimize his Express app to handle static files efficiently. Which built-in middleware should he use?
- a)
app.use('/static', express.static())
- b)
app.use(express.json())
- c)
app.use(express.urlencoded())
- d)
app.use('/files', express.static())
app.use('/static', express.static())
- a)
Nina is using React components to create a list of user profiles from an API. Which lifecycle hook should she use to fetch the data when the component mounts?
- a)
useLayoutEffect
- b)
useEffect
- c)
useState
- d)
useMemo
Answer: b)
useEffect
- a)
- Daniel is creating a form that submits data to his Express server. Which HTTP method should he use to submit the data if he wants to create a new resource?
- a) GET
- b) POST
- c) PUT
- d) DELETE
- Sophia is working on a PWA for offline functionality. Which API should she use to cache assets and data for offline access?
- a)
Fetch API
- b)
Service Worker API
- c)
Local Storage
- d)
Session Storage
Answer: b) Service Worker API
No comments:
Post a Comment