Stock market simulator

React
Medium

Objective

Complete a React component that simulates a mini stock market.

Your market has three stocks, and their prices should fluctuate over time.

Requirements

  1. Implement two actions in the stockMarketReducer

    1. UPDATE_PRICE: randomly increase or decrease the price of a selected stock by between 1-5%

    2. RESET_MARKET: resets all stock prices to their initial values

  2. Complete the StockMarket component so it renders:

    1. The current stock prices

    2. A button next to each stock, labelled "Update price" which will update the stock price

    3. A button labelled "Reset market" which will reset the prices back to their original values

Starting code

import React, { useReducer } from 'react'; function stockMarketReducer (state, action) { // Your code here } function StockMarket () { const [state, dispatch] = useReducer(stockMarketReducer, { ADM: 2372.50, IHG: 6166.81, RR: 224.57, }); // Your code here return null; } export default StockMarket;