【发布时间】:2020-11-24 14:28:31
【问题描述】:
我有一个如下所示的初始状态 const 项:
const INITIAL_STATE = {
endPoint: { street: '', coordinates: [] }, //[13.3969, 52.5182]
startingPoint: { street: '', coordinates: [] }, //[13.413215, 52.521918]
favouritePoint: { street: '', coordinates: [] },
favouriteLocations: {getFavouritePlaces()},
// favouriteLocations: [
// {
// name: 'Zu Hause',
// street: 'Müllersweg',
// coordinates: [8.217462, 53.13975], //[8.258844, 53.119525],
// },
// {
// name: 'Büro',
// street: 'Philipp-Reis-Gang',
// coordinates: [8.258844, 53.119525], //[8.217462, 53.13975],
// },
// {
// name: 'KaffeeHaus',
// street: 'Cloppenburgerstr.',
// coordinates: [8.211, 53.113],
// },
// ],
addressesFoundList: [],
};
我尝试调用 favouriteLocations 的函数,而不是硬编码值,该函数将返回相同类型的对象。但是,目前这不会调用我的函数。
我的函数如下所示:
const getFavouritePlaces = () => {
return ...
}
稍后,我将在我的 redux 设置中使用这个初始状态。
【问题讨论】:
-
那不是有效的javascript,我认为
favouriteLocations: {getFavouritePlaces()},应该是:favouriteLocations: getFavouritePlaces(), -
这能回答你的问题吗? How to call a constant as a function name?
-
即便如此,我也无法实现我想要的。因为我在函数内部使用了一个钩子,所以当我在这里调用它时,它给了我一个无效的钩子错误stackoverflow.com/questions/63248118/…@HMR
标签: javascript reactjs typescript react-native redux