ReactComponent
Defined in: parser/types.ts:822
The ReactComponent interface is used to define the properties of a react component. This component is used to render react code with certain parameters. These parameters can be used within your react code to render different things.
Unlike other types of components, the path for a React component is relative to the src/public/
folder.
Similar to our standard assets, we suggest creating a folder named src/public/{studyName}/assets
to house all of the React component assets for a particular study.
Your React component which you link to in the path must be default exported from its file.
React components created this way have a generic prop type passed to the component on render, <StimulusParams<T>>
, which has the following types.
{
parameters: T;
setAnswer: ({ status, provenanceGraph, answers }: { status: boolean, provenanceGraph?: TrrackedProvenance, answers: Record<string, any> }) => void
}
parameters is the same object passed in from the ReactComponent type below, allowing you to pass options in from the config to your component. setAnswer is a callback function allowing the creator of the ReactComponent to programmatically set the answer, as well as the provenance graph. This can be useful if you don't use the default answer interface, and instead have something more unique.
So, for example, if I had the following ReactComponent in my config
{
type: 'react-component';
path: 'my_study/CoolComponent.tsx';
parameters: {
name: 'Zach';
age: 26;
}
}
My react component, CoolComponent.tsx, would exist in src/public/my_study/assets, and look something like this
export default function CoolComponent({ parameters, setAnswer }: StimulusParams<{name: string, age: number}>) {
// render something
}
For in depth examples, see the following studies, and their associated codebases. https://revisit.dev/study/demo-click-accuracy-test (https://github.com/revisit-studies/study/tree/v2.2.0/src/public/demo-click-accuracy-test/assets) https://revisit.dev/study/example-brush-interactions (https://github.com/revisit-studies/study/tree/v2.2.0/src/public/example-brush-interactions/assets)
Extends
Properties
Property | Type | Description | Inherited from | Defined in |
---|---|---|---|---|
allowFailedTraining? | boolean | Controls whether the component should allow failed training. If present, will override the allow failed training setting in the uiConfig. | BaseIndividualComponent .allowFailedTraining | parser/types.ts:743 |
correctAnswer? | Answer [] | The correct answer to the component. This is used for training trials where the user is shown the correct answer after a guess. | BaseIndividualComponent .correctAnswer | parser/types.ts:703 |
description? | string | The description of the component. This is used to identify and provide additional information for the component in the admin panel. | BaseIndividualComponent .description | parser/types.ts:707 |
enumerateQuestions? | boolean | Whether to prepend questions with their index (+ 1). This should only be used when all questions are in the same location, e.g. all are in the side bar. If present, will override the enumeration of questions setting in the uiConfig. | BaseIndividualComponent .enumerateQuestions | parser/types.ts:749 |
helpTextPath? | string | The path to the help text file. This is displayed when a participant clicks help. Markdown is supported. If present, will override the help text path set in the uiConfig. | BaseIndividualComponent .helpTextPath | parser/types.ts:723 |
instruction? | string | The instruction of the component. This is used to identify and provide additional information for the component in the admin panel. | BaseIndividualComponent .instruction | parser/types.ts:719 |
instructionLocation? | ConfigResponseBlockLocation | The location of the instructions. If present, will override the instruction location setting in the uiConfig. | BaseIndividualComponent .instructionLocation | parser/types.ts:721 |
meta? | Record <string , unknown > | The meta data for the component. This is used to identify and provide additional information for the component in the admin panel. | BaseIndividualComponent .meta | parser/types.ts:705 |
nextButtonDisableTime? | number | The time in milliseconds to wait before the next button is disabled. If present, will override the next button disable time setting in the uiConfig. | BaseIndividualComponent .nextButtonDisableTime | parser/types.ts:733 |
nextButtonEnableTime? | number | The time in milliseconds to wait before the next button is enabled. If present, will override the next button enable time setting in the uiConfig. | BaseIndividualComponent .nextButtonEnableTime | parser/types.ts:731 |
nextButtonLocation? | ConfigResponseBlockLocation | The location of the next button. If present, will override the next button location setting in the uiConfig. | BaseIndividualComponent .nextButtonLocation | parser/types.ts:729 |
nextButtonText? | string | The text to display on the next button. If present, will override the next button text setting in the uiConfig. | BaseIndividualComponent .nextButtonText | parser/types.ts:727 |
nextOnEnter? | boolean | Whether enter key should move to the next question. If present, will override the enter key setting in the uiConfig. | BaseIndividualComponent .nextOnEnter | parser/types.ts:725 |
parameters? | Record <string , unknown > | The parameters that are passed to the react component. These can be used within your react component to render different things. | - | parser/types.ts:827 |
path | string | The path to the react component. This should be a relative path from the src/public folder. | - | parser/types.ts:825 |
previousButton? | boolean | Whether to show the previous button. If present, will override the previous button setting in the uiConfig. | BaseIndividualComponent .previousButton | parser/types.ts:735 |
previousButtonText? | string | The text that is displayed on the previous button. If present, will override the previous button text setting in the uiConfig. | BaseIndividualComponent .previousButtonText | parser/types.ts:737 |
provideFeedback? | boolean | Controls whether the component should provide feedback to the participant, such as in a training trial. If present, will override the provide feedback setting in the uiConfig. | BaseIndividualComponent .provideFeedback | parser/types.ts:739 |
recordAudio? | boolean | Whether or not we want to utilize think-aloud features. If present, will override the record audio setting in the uiConfig. | BaseIndividualComponent .recordAudio | parser/types.ts:745 |
recordScreen? | boolean | Whether or not we want to utilize screen recording feature. If present, will override the record screen setting in the uiConfig. If true, the uiConfig must have recordScreen set to true or the screen will not be captured. It's also required that the library component, $screen-recording.co.screenRecordingPermission, be included in the study at some point before this component to ensure permissions are granted and screen capture has started. | BaseIndividualComponent .recordScreen | parser/types.ts:747 |
response | Response [] | The responses to the component | BaseIndividualComponent .response | parser/types.ts:699 |
responseDividers? | boolean | Whether to show the response dividers. If present, will override the response dividers setting in the uiConfig. | BaseIndividualComponent .responseDividers | parser/types.ts:751 |
responseOrder? | "fixed" | "random" | The order of the responses. Defaults to 'fixed'. | BaseIndividualComponent .responseOrder | parser/types.ts:755 |
showTitle? | boolean | Controls whether the title should be hidden in the study. If present, will override the title setting in the uiConfig. | BaseIndividualComponent .showTitle | parser/types.ts:715 |
showTitleBar? | boolean | Controls whether the title bar should be hidden in the study. If present, will override the title bar setting in the uiConfig. | BaseIndividualComponent .showTitleBar | parser/types.ts:717 |
sidebarWidth? | number | The width of the left sidebar. If present, will override the sidebar width setting in the uiConfig. | BaseIndividualComponent .sidebarWidth | parser/types.ts:713 |
style? | Styles | You can set styles here, using React CSSProperties, for example: {"width": 100} or {"width": "50%"} | BaseIndividualComponent .style | parser/types.ts:759 |
stylesheetPath? | string | The path to the external stylesheet file. | BaseIndividualComponent .stylesheetPath | parser/types.ts:757 |
trainingAttempts? | number | The number of training attempts allowed for the component. If present, will override the training attempts setting in the uiConfig. | BaseIndividualComponent .trainingAttempts | parser/types.ts:741 |
type | "react-component" | - | - | parser/types.ts:823 |
windowEventDebounceTime? | number | Debounce time in milliseconds for automatically tracked window events. If present, will override the window event debounce time setting in the uiConfig. | BaseIndividualComponent .windowEventDebounceTime | parser/types.ts:753 |
withProgressBar? | boolean | Controls whether the progress bar is rendered. If present, will override the progress bar setting in the uiConfig. | BaseIndividualComponent .withProgressBar | parser/types.ts:709 |
withSidebar? | boolean | Controls whether the left sidebar is rendered at all. Required to be true if your response's location is set to sidebar for any question. If present, will override the sidebar setting in the uiConfig. | BaseIndividualComponent .withSidebar | parser/types.ts:711 |