If you want to call a function in the placeholder of an input:
jsx<input placeholder = {functionName()}/>
As an example, I've created a component in React displaying an input with a placeholder depending on the day of the week:
jsximport React, { useState } from 'react'; const DayOfTheWeek = () => { const [name, setName] = useState(''); const dayOfTheWeek = () => { let today = new Date(); let dayOfWeek = today.getDay(); let weekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; return `Type: ${weekDays[dayOfWeek]}`; } return( <input onChange = {(e) => setName(e.target.value)} value = {name} placeholder = {dayOfTheWeek()} /> ); } export default DayOfTheWeek;
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.