colossal-harlequinC
Refine2y ago
21 replies
colossal-harlequin

Accessing data using useone

This is my .tsx file
import { Typography, Spin, Alert } from "antd";
import { useOne } from "@refinedev/core";
import { getUser } from "../../utils/CommonFunctions";
import Profile from "../../components/profile/Profile";

interface UserProfile {
name: string;
email: string;
avatar: string;
}

const { Text } = Typography;

const MyProfile = () => {
const user = getUser();

const { data, isLoading, isError } = useOne({
resource: "users",
id: user?.userid,
});

const myProfile = data?.data ?? [];

if (isLoading) return <Spin size="large" />;
if (isError) return <Alert message="Error loading profile" type="error" />;

return (
<Profile
type="My"
name={myProfile.name}
email={myProfile.email}
avatar={myProfile.avatar}
/>
);
};

export default MyProfile;

at these lines
name={myProfile.name}
email={myProfile.email}
avatar={myProfile.avatar}
i get following error
Property 'name' does not exist on type 'BaseRecord | never[]'.
Property 'name' does not exist on type 'never[]'.ts(2339)
Was this page helpful?