Aller au contenu principal

Type Alias: LunaticState

LunaticState: object

Return type of useLunatic.

Allow to operate the survey.

Type declaration

compileControls()

compileControls: () => object

Allow to fetch controls.

Returns

object

currentErrors

currentErrors: Record<string, LunaticError[]> | undefined

isCritical

isCritical: boolean

currentErrors?

optional currentErrors: object

Errors in the current page / iteration.

Index Signature

[id: string]: LunaticError[]

errors?

optional errors: object

Errors in the survey.

Index Signature

[page: string]: object

getChangedData()

getChangedData: (reset?) => LunaticData

Get data that have changed since last reset. Returns the same thing as getData().

Parameters

ParameterType
reset?boolean

Returns

LunaticData

getComponents()

getComponents: () => LunaticComponentProps[]

Components to display in the current page.

Return an array with the various components' properties. The orchestrator has to handle how they are displayed, using the componentType property to select the appropriate component.

Returns

LunaticComponentProps[]

Examples

// using `LunaticComponents`
import { useLunatic, LunaticComponents } from '@inseefr/lunatic';

function App({ source, data }) {
const { getComponents, Provider } = useLunatic(source, data, {});
const components = getComponents();

return (
<Provider>
<LunaticComponents components={components} />
</Provider>
);
}
// using custom components
import { useLunatic, LunaticComponents } from '@inseefr/lunatic';

const customCompoonents = {
Input: MyCustomInput,
InputNumber: MyCustomInputNumber,
};

function App({ source, data }) {
const { getComponents, Provider } = useLunatic(source, data, {});
const components = getComponents();

return (
<Provider>
<LunaticComponents components={components} slots={customComponents} />
</Provider>
);
}

See

LunaticComponents

getData()

getData: (withRefreshedCalculated, variableNames?) => LunaticData

Get data collected by the survey.

Parameters

ParameterType
withRefreshedCalculatedboolean
variableNames?string[]

Returns

LunaticData

goNextPage()

goNextPage: () => void

Navigate to the next page.

Returns

void

goPreviousPage()

goPreviousPage: () => void

Navigate to the previous page.

Returns

void

goToPage()

goToPage: (page) => void

Navigate to a specific page.

Parameters

ParameterType
pageobject
page.iteration?number
page.nbIterations?number
page.pagePageTag | number
page.subPage?number

Returns

void

hasPageResponse()

hasPageResponse: () => boolean

Return true as soon as the current page has at least one answer.

Returns

boolean

isFirstPage

isFirstPage: boolean

Whether or not we're on the survey first page.

isInLoop

isInLoop: boolean

Whether or not we're in a loop.

isLastPage

isLastPage: boolean

Whether or not we're on the survey last page (we reached maxPage).

loopVariables

loopVariables: string[]

Current loop's variables.

modalErrors?

optional modalErrors: Record<string, LunaticError[]>

Errors in modal.

overview

overview: InterpretedLunaticOverviewItem[]

pager

pager: LunaticPager

Current pager.

pageTag

pageTag: PageTag

Current page numerotation.

Provider

Provider: FunctionComponent<PropsWithChildren>

Necessary component that must wraps LunaticComponents to make the library works.

resetChangedData()

resetChangedData: () => void

Empty the store of changed variables.

Returns

void

testing

testing: object

Used for testing purpose only.

testing.handleChanges

handleChanges: LunaticChangesHandler

updatedAt

updatedAt: number

Date of the last handleChange function call.

Defined in

src/use-lunatic/type.ts:244