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
Implement two actions in the
stockMarketReducer
UPDATE_PRICE
: randomly increase or decrease the price of a selected stock by between 1-5%RESET_MARKET
: resets all stock prices to their initial values
Complete the
StockMarket
component so it renders:The current stock prices
A button next to each stock, labelled "Update price" which will update the stock price
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;