最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - React & Framer builder, use code override to change text - Stack Overflow

programmeradmin3浏览0评论

Im creating code override to change the text of component, for now it fully replaces the text as Im changing the children prop, but with replacing children, it also resets all other props like text styles, is there any other way to change text and keep the styles?

function SetCurrentUsd(props: Props): ReactNode {
  const { initialUsd } = props;

  const [usd, setUsd] = useState<string | number>("");

  useEffect(() => {
    // my fetch data logic here
   setUsd(data.response)
  }, [initialUsd]);

  return <>{usd}</>;
}

export function set50Usd(): Override {
    return {
        children: <SetCurrentUsd initialUsd={50} />,
    }
}

export function set100Usd(): Override {
    return {
        children: <SetCurrentUsd initialUsd={100} />,
    }
}

export function set500Usd(): Override {
    return {
        children: <SetCurrentUsd initialUsd={500} />,
    }
}

export function set1000Usd(): Override {
    return {
        children: <SetCurrentUsd initialUsd={1000} />,
    }
}

Im creating code override to change the text of component, for now it fully replaces the text as Im changing the children prop, but with replacing children, it also resets all other props like text styles, is there any other way to change text and keep the styles?

function SetCurrentUsd(props: Props): ReactNode {
  const { initialUsd } = props;

  const [usd, setUsd] = useState<string | number>("");

  useEffect(() => {
    // my fetch data logic here
   setUsd(data.response)
  }, [initialUsd]);

  return <>{usd}</>;
}

export function set50Usd(): Override {
    return {
        children: <SetCurrentUsd initialUsd={50} />,
    }
}

export function set100Usd(): Override {
    return {
        children: <SetCurrentUsd initialUsd={100} />,
    }
}

export function set500Usd(): Override {
    return {
        children: <SetCurrentUsd initialUsd={500} />,
    }
}

export function set1000Usd(): Override {
    return {
        children: <SetCurrentUsd initialUsd={1000} />,
    }
}
Share Improve this question asked Feb 17 at 8:59 user22592696user22592696 214 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You need to pass and accept props in your setter function:

export function set50Usd({...props}:unknown): Override {
    return {
        ...props,
        children: <SetCurrentUsd initialUsd={50} />,
    }
}

second guess:

export function set50Usd({...props}:unknown): Override {
    return {
        children: <SetCurrentUsd initialUsd={50} {...props} />,
    }
}
发布评论

评论列表(0)

  1. 暂无评论