如何调用与参数具有相同名称的函数
How to call a function which has a same name with a parameter
我是新手。我想从其他 .js 文件调用一个函数,该文件与仪表板函数中的参数同名。但它显示 TypeError: getCurrentProfile is not a function。非常感谢任何提示和帮助!
例如:
import { getCurrentProfile } from '../actions/profile';
const Dashboard = ({
getCurrentProfile,
auth: { user }
}) => {
useEffect(() => {
getCurrentProfile();
}, []);
return(
<Fragment>
<h1> DAshboard</h1>
<i className='das fa-user'></i><p>Welcome {user && user.name}</p>
</Fragment>
);
};
错误:
类型错误:getCurrentProfile 不是函数
您需要确保不会发生名称冲突。您可以重命名导入,或重命名解构的道具,或者根本不解构道具。
实际上,似乎根本没有使用 getCurrentProfile
属性,因此您可以将其从参数列表中删除:
const Dashboard = ({
auth: { user }
}) => {
useEffect(getCurrentProfile, []);
return (
<Fragment>
<h1> DAshboard</h1>
<i className='das fa-user'></i><p>Welcome {user && user.name}</p>
</Fragment>
);
};
如果你真的在某处使用 getCurrentProfile
道具,那么你可以做
const Dashboard = (props) => {
const { user } = props.auth;
useEffect(getCurrentProfile, []);
您可以在导入中使用“as”。
import { getCurrentProfile as Alias } from '../actions/profile';
然后在您的挂钩中使用该别名
useEffect(() => {
Alias();
}, []);
我是新手。我想从其他 .js 文件调用一个函数,该文件与仪表板函数中的参数同名。但它显示 TypeError: getCurrentProfile is not a function。非常感谢任何提示和帮助!
例如:
import { getCurrentProfile } from '../actions/profile';
const Dashboard = ({
getCurrentProfile,
auth: { user }
}) => {
useEffect(() => {
getCurrentProfile();
}, []);
return(
<Fragment>
<h1> DAshboard</h1>
<i className='das fa-user'></i><p>Welcome {user && user.name}</p>
</Fragment>
);
};
错误: 类型错误:getCurrentProfile 不是函数
您需要确保不会发生名称冲突。您可以重命名导入,或重命名解构的道具,或者根本不解构道具。
实际上,似乎根本没有使用 getCurrentProfile
属性,因此您可以将其从参数列表中删除:
const Dashboard = ({
auth: { user }
}) => {
useEffect(getCurrentProfile, []);
return (
<Fragment>
<h1> DAshboard</h1>
<i className='das fa-user'></i><p>Welcome {user && user.name}</p>
</Fragment>
);
};
如果你真的在某处使用 getCurrentProfile
道具,那么你可以做
const Dashboard = (props) => {
const { user } = props.auth;
useEffect(getCurrentProfile, []);
您可以在导入中使用“as”。
import { getCurrentProfile as Alias } from '../actions/profile';
然后在您的挂钩中使用该别名
useEffect(() => {
Alias();
}, []);