opendevs
useEffect to set timer

useEffect to update DOM

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

Difficulty

easy

Solve the practice problems to earn    DevCoin image 
Coding Area
Output

Copyright © 2022 opendevs

Learn ● Develop ● Ace
All illustrations by Storyset