opendevs logo

useEffect to update DOM

Solidify your knowledge of Component Lifecycle Phases by solving this problem.
useEffect to set timer

Dogendar 🐶 is given a React component PageTitle that is supposed to update the title of the page (it's the text that you see in the browser tab). Dogendar is aware that he can set the page title using document.title = 'new title'.

The component takes two props pageTitle and setPageTitle. pageTitle is a string which is to be set as the page title and setPageTitle is a function that can be used to set the title of the page. It is implemented as

const setPageTitle = (newTitle) => { document.title = newTitle }

Help Dogendar finish the component and fulfil these requirements:

  • Set page title to the value passed in prop using setPageTitle function
  • Update page title using setPageTitle function whenever value in prop changes, i.e. when pageTitle changes
  • Do NOT unnecessarily set title using setPageTitle function if value in prop does NOT change

Solve this easy problem to earn  1  DevCoin image
Coding Area
opendevs logo
CoursesFAQsContact UsPrivacy PolicyTerms Of Service
Copyright © 2023 opendevs
Learn ● Develop ● Ace
All illustrations by Storyset