Error to destructure useLocalization Hook

1 Answer 60 Views
General Discussions
Gabriel
Top achievements
Rank 2
Iron
Gabriel asked on 06 Jun 2023, 02:22 PM

Hello guys,


I realized that it's not possible to destructure the useLocalization hook, when destructure, it causes an error. I made an example to demonstrate the problem.

const { toLanguageString } = useLocalization(); //THROW AN ERROR
const localization = useLocalization(); //NORMAL

xenodochial-dan-prqfvt - CodeSandbox

Is this actually expected or is it just a bug?

Thanks,

Gabriel.


1 Answer, 1 is accepted

Sort by
0
Accepted
Wissam
Telerik team
answered on 08 Jun 2023, 05:37 AM

Hi, Gabriel,

Thank you for the provided example.

This is expected since useLocalization is a custom React hook that provides access to the LocalizationService class component that has `toLanguageString` as a function.

Basically, destructing is only possible for objects and arrays.

For more information about Javascript destructuring, you can check this article or a similar one:

Please let me know if you have any further questions on this matter.

Regards,
Wissam
Progress Telerik

As of R2 2023, the default icon type will be SVG instead of Font. See this blogpost for more information.
Tags
General Discussions
Asked by
Gabriel
Top achievements
Rank 2
Iron
Answers by
Wissam
Telerik team
Share this question
or