How to access props inside quotes in React JSX?
Following approaches are there to access props inside quotes in React JSX:
- Approach 1: We can put any JS expression inside curly braces as the entire attribute value.
- Approach 2: We can use ES6 template literals.
Creating React Application:
Step 1: Create a React application using the following command:
npx create-react-app foldername
Step 2: After creating your project folder i.e. foldername, move to it using the following command:
Project Structure: It will look like the following.
Approach 1: App.js
Approach 2: App.js
Note: Make sure to pass the prop value in the <App> component in the index.js file and place any sample picture in the public folder, like here we have used reactLogo.png.
Step to Run Application: Run the application using the following command from the root directory of the project:
Output: You will see the reactLogo.png picture on your browser screen.