In javascript and React Native, I use an API function which returns two elements: results
and error
.
import { findAll as forumFindAll } from '../../Api/ForumApi'
const IndexScreen = () => {
const [results, error] = forumFindAll()
...
I would like to rename the variables results
and error
on a single line (much like destructuring).
Something like that (but I know it doesn't work) :
const [results as forumsResults, error as forumsError] = forumFindAll()
In javascript and React Native, I use an API function which returns two elements: results
and error
.
import { findAll as forumFindAll } from '../../Api/ForumApi'
const IndexScreen = () => {
const [results, error] = forumFindAll()
...
I would like to rename the variables results
and error
on a single line (much like destructuring).
Something like that (but I know it doesn't work) :
const [results as forumsResults, error as forumsError] = forumFindAll()
Share
Improve this question
edited Sep 3, 2022 at 14:52
Penny Liu
17.4k5 gold badges86 silver badges108 bronze badges
asked Mar 27, 2020 at 6:41
Gaylord.PGaylord.P
1,4684 gold badges28 silver badges71 bronze badges
1 Answer
Reset to default 17Since forumFindAll
returns an array, there should be no need to "rename" any of its items - simply put in the names you want into the destructuring syntax:
const [forumsResults, forumsError] = forumFindAll();
The return value of forumFindAll
does not have any intrinsic connection to the results
and error
names, you can choose whatever names you wish.