30秒学会 React 片段 · 2023年8月20日

30秒学会 React 片段 – Callable telephone link

Renders a link formatted to call a phone number (tel: link).

  • Use phone to create a <a> element with an appropriate href attribute.
  • Render the link with children as its content.

代码实现

const Callto = ({ phone, children }) => {
  return <a href={`tel:${phone}`}>{children}</a>;
};

使用样例

ReactDOM.createRoot(document.getElementById('root')).render(
  <Callto phone="+302101234567">Call me!</Callto>
);

翻译自:https://www.30secondsofcode.org/react/s/callto