1

我正在为 React 中的高阶组件而苦苦挣扎。我正在尝试使用Solidreact-components加载用户的个人资料数据useLDflex()。我的代码抛出了一个我无法理解的错误;我不确定问题是否与 React、高阶组件或 Solid 的库有关。任何人都可以帮忙吗?

代码(反应/TSX):

import { useLDflex } from '@solid/react';
import React from 'react';

class Profile extends React.Component<{name: string}, {}> {
    render() {
        return (
            <main role="Profile">
                <div className="container">
                    Name: {this.props.name}
                </div>
            </main>
        )
    }
}

interface IProfileId {
    profileId: string;
}

const withName = (Component: any) => ({profileId}: IProfileId) => {
    const webId = `https://${profileId}.solidcommunity.net/profile/card#me`;
    const [name, namePending, nameError] = useLDflex(`[${webId}].name`);
    return <Component name={name} />
}

export const newProfile = withName(Profile);

错误(在线):

Error: Specify at least one term when calling .next() on a path
4

1 回答 1

1

解决了。问题是name在从 Solid 服务器加载配置文件时处于未知/未定义状态。这是工作代码:

import { useLDflexValue } from '@solid/react';
import React from 'react';

class P extends React.Component<{name: string}, {}> {
    render() {
        return (
            <main role="Profile">
                <div className="container">
                    Name: {this.props.name}
                </div>
            </main>
        )
    }
}

const withName = (Component: any) => ({profileId}: {profileId: string}) => {
    const webId = `https://${profileId}.solidcommunity.net/profile/card#me`;
    const name = useLDflexValue(`[${webId}].name`)?.toString() || 'loading...';
    return <Component name={name} />
}

export const Profile = withName(P);
于 2021-03-05T03:08:14.577 回答