Skip to content
Advertisement

function is declared but its value is never read : React

I am new to Reactjs so forgive me if this is lame. I am following the Reactjs docs for learning React and during the self implementation of exercise in components and props. And I encountered following weird behaviour: In the ‘Comment’ function <UserInfo ../> tag is working fine but <commentText ../> and <commentDate ../> is not working and for their respective functions VScode is saying that they are declared but their value is never used.

JavaScript
JavaScript

Advertisement

Answer

Rename:

function commentText(props){

to

function CommentText(props){

and:

function commentDate(props) {

to

function CommentDate(props) {

Then:

JavaScript

React components are different from regular functions such that their first letter must be capital. It is good practice to structure react components as:

const CommentDate = (props) => {}

instead of

function CommentDate(props) {}

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement