С компонентом класса я обычно создаю экземпляр этого компонента и могу получить доступ к функции. Я не уверен, как получить доступ к функции функционального компонента.
const errorMessages = { browse: { fileLimit: 'File size is too big.', unsupportedFormat: 'The file you selected is not a supported format. Please upload a file in .csv format.', noRows: 'No agent IDS could be found.', maxAgents: 'A max of 25 agents can be uploaded at a time.', noValidAgents: 'No valid agents could be found.' }, duplicate: 'The following agents are already existing on the table.' };
const uploadbutton = (ofs, ref) = > {const mimeTypes = [‘text/csv’, ‘application/vnd.ms-excel’]; позволять; const [rowseerror, (initialValue); const [uploadError, (initialValue); const [duplicateError, (initialValue); const [загрузка, (false); const (initialValue);
const clearAllErrors = () => { setBrowseError(initialValue); setUploadError(initialValue); setDupplicateError(initialValue); }
…. }
Таким образом, доступ к ClearAlgerrors, например, или ошибки, которые за пределами функционального компонента.
Оригинал: “https://dev.to/lshawa/how-do-we-unit-test-functions-within-a-functional-component-4h09”