Callable Telephone Link

ReactReactBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

In this lab, we will learn how to create a callable telephone link in React using the tel: protocol. This link allows users to call a phone number directly from their device with just one click. By the end of this lab, you will be able to implement this feature into your own React applications, enhancing their usability and accessibility.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL react(("`React`")) -.-> react/FundamentalsGroup(["`Fundamentals`"]) react/FundamentalsGroup -.-> react/jsx("`JSX`") subgraph Lab Skills react/jsx -.-> lab-38342{{"`Callable Telephone Link`"}} end

index.html and script.js have already been provided in the VM. In general, you only need to add code to script.js and style.css.

To create a link that calls a phone number, use the Callto component. This component creates an <a> element with an appropriate href attribute. To render the link, specify the phone number using the phone prop, and the link text using the children prop.

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

To use the Callto component, call the ReactDOM.render() method and pass in the Callto element with the phone and children props set.

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

Please click on 'Go Live' in the bottom right corner to run the web service on port 8080. Then, you can refresh the Web 8080 Tab to preview the web page.

Summary

Congratulations! You have completed the Callable Telephone Link lab. You can practice more labs in LabEx to improve your skills.

Other React Tutorials you may like