The stock market is unpredictable. In case of urgency, you may be forced to sell your investments even if the market is low. Hence you should keep a separate emergency fund with banks that you can access whenever required. The banks offer fixed deposits schemes that allow you to withdraw before maturity too.
You should never invest your emergency fund in the stock market.
If you want to learn more check out these resources: