2023-10-09 16:23:16 +00:00
|
|
|
import { QuestionTypes } from '../utils';
|
|
|
|
|
|
|
|
|
|
import type { ExerciseTemplate } from '$lib/utils/types';
|
|
|
|
|
|
|
|
|
|
const template: ExerciseTemplate = {
|
|
|
|
|
title: 'React State Sharing Practical Quiz',
|
|
|
|
|
description: 'Test your practical knowledge of sharing state between components in React.',
|
|
|
|
|
questionnaire: {
|
|
|
|
|
questions: [
|
|
|
|
|
{
|
|
|
|
|
title: 'What is the primary purpose of using props to share data between React components?',
|
|
|
|
|
name: 'propsPurpose',
|
|
|
|
|
points: 1,
|
|
|
|
|
order: 0,
|
|
|
|
|
question_type: QuestionTypes[0],
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: 'To pass data from a parent component to its child components.',
|
2023-11-25 21:56:02 +00:00
|
|
|
is_correct: true
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'To pass data from a child component to its parent components.',
|
2023-11-25 21:56:02 +00:00
|
|
|
is_correct: false
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'To create local component data.',
|
2023-11-25 21:56:02 +00:00
|
|
|
is_correct: false
|
|
|
|
|
}
|
|
|
|
|
]
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'What is the recommended way to pass a function as a prop in React?',
|
|
|
|
|
name: 'passingFunctionAsProp',
|
|
|
|
|
points: 1,
|
|
|
|
|
order: 1,
|
|
|
|
|
question_type: QuestionTypes[0],
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: 'Create a function in the child component and call it in the parent component.',
|
2023-11-25 21:56:02 +00:00
|
|
|
is_correct: false
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Pass the function as a prop from the parent component to the child component.',
|
2023-11-25 21:56:02 +00:00
|
|
|
is_correct: true
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Use a global variable to share the function.',
|
2023-11-25 21:56:02 +00:00
|
|
|
is_correct: false
|
|
|
|
|
}
|
|
|
|
|
]
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'What is a common use case for using context to share state in React?',
|
|
|
|
|
name: 'contextUseCase',
|
|
|
|
|
points: 1,
|
|
|
|
|
order: 2,
|
|
|
|
|
question_type: QuestionTypes[2],
|
2023-11-25 21:56:02 +00:00
|
|
|
options: []
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'How can you share state between components using React Context?',
|
|
|
|
|
name: 'sharingStateWithContext',
|
|
|
|
|
points: 1,
|
|
|
|
|
order: 3,
|
|
|
|
|
question_type: QuestionTypes[0],
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: 'Wrap the components with a Context Provider and use the useContext hook.',
|
2023-11-25 21:56:02 +00:00
|
|
|
is_correct: true
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Pass the state as a prop to each component.',
|
2023-11-25 21:56:02 +00:00
|
|
|
is_correct: false
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Use Redux for state management.',
|
2023-11-25 21:56:02 +00:00
|
|
|
is_correct: false
|
|
|
|
|
}
|
|
|
|
|
]
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'What is the purpose of the "useReducer" hook in React?',
|
|
|
|
|
name: 'useReducerPurpose',
|
|
|
|
|
points: 1,
|
|
|
|
|
order: 4,
|
|
|
|
|
question_type: QuestionTypes[2],
|
2023-11-25 21:56:02 +00:00
|
|
|
options: []
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'How does the "useReducer" hook differ from the "useState" hook in React?',
|
|
|
|
|
name: 'useReducerVsUseState',
|
|
|
|
|
points: 1,
|
|
|
|
|
order: 5,
|
|
|
|
|
question_type: QuestionTypes[1],
|
|
|
|
|
options: [
|
|
|
|
|
{
|
2023-11-25 21:56:02 +00:00
|
|
|
label:
|
|
|
|
|
'useReducer is used for managing complex state logic, while useState is for simple state.',
|
|
|
|
|
is_correct: true
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
2023-11-25 21:56:02 +00:00
|
|
|
label:
|
|
|
|
|
'useState is used for managing complex state logic, while useReducer is for simple state.',
|
|
|
|
|
is_correct: false
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'There is no difference between them.',
|
2023-11-25 21:56:02 +00:00
|
|
|
is_correct: false
|
|
|
|
|
}
|
|
|
|
|
]
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'What is the purpose of the "prop drilling" problem in React?',
|
|
|
|
|
name: 'propDrillingPurpose',
|
|
|
|
|
points: 1,
|
|
|
|
|
order: 6,
|
|
|
|
|
question_type: QuestionTypes[2],
|
2023-11-25 21:56:02 +00:00
|
|
|
options: []
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'How can you avoid prop drilling in React?',
|
|
|
|
|
name: 'avoidingPropDrilling',
|
|
|
|
|
points: 1,
|
|
|
|
|
order: 7,
|
|
|
|
|
question_type: QuestionTypes[0],
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: 'Use context to share state.',
|
2023-11-25 21:56:02 +00:00
|
|
|
is_correct: true
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Always pass props directly to the child components.',
|
2023-11-25 21:56:02 +00:00
|
|
|
is_correct: false
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Use global variables to store state.',
|
2023-11-25 21:56:02 +00:00
|
|
|
is_correct: false
|
|
|
|
|
}
|
|
|
|
|
]
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'What is the purpose of using Redux for state management in React applications?',
|
|
|
|
|
name: 'reduxPurpose',
|
|
|
|
|
points: 1,
|
|
|
|
|
order: 8,
|
|
|
|
|
question_type: QuestionTypes[2],
|
2023-11-25 21:56:02 +00:00
|
|
|
options: []
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: 'What is the role of a Redux reducer function?',
|
|
|
|
|
name: 'reduxReducerRole',
|
|
|
|
|
points: 1,
|
|
|
|
|
order: 9,
|
|
|
|
|
question_type: QuestionTypes[0],
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
label: 'To specify how the state should change in response to actions.',
|
2023-11-25 21:56:02 +00:00
|
|
|
is_correct: true
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'To define the initial state of the application.',
|
2023-11-25 21:56:02 +00:00
|
|
|
is_correct: false
|
2023-10-09 16:23:16 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'To connect React components to the Redux store.',
|
2023-11-25 21:56:02 +00:00
|
|
|
is_correct: false
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2023-10-09 16:23:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default template;
|