'Metamask - switch to ropsten network using react js

i'm developping a web 3.0 app and i want when users connect there metamask, if the network i not ropsten then metamask ask them to switch it cause my smart contract was deployed into ropsten network and i want all the transactions pass in ropsten network, but i faced some problemes and i didn't found the solution anywhere else [enter image description here][1]

This is the function which handle the switch network function : https://i.stack.imgur.com/R6QpY.png

This is the error that i faced : https://i.stack.imgur.com/76DbN.png

Any Help pleaaaase !



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source