An avocado will keep a few days in the refrigerator after it has been cut. The cut portion will turn brown/black due to oxidation, you can just cut that off, it is not harmful.
From California Avocado Commission to keep the avocado from discoloring sprinkle it with lemon/lime juice or vinegar and wrap tightly in plastic wrap or place in an airtight container.
From thekitchn storing a cut avocado with a piece of cut onion in an airtight container will stop the oxidation.
I don't know why this is, but I suspect that it has to do with the sulfur compounds that the onion releases. This is the same sulfur that makes you cry when you chop onions, but it is also used as a preservative. The onion's smell and taste don't seem to transfer to the avocado, as far as I can tell. But I'm not overly sensitive to onions, so you may want to check this out first if you are.
When not to use, from WebMD
if your avocado's flesh has become very dark or the flesh has become stringy you should avoid eating it, particularly if there is any sign of mold. Avocados have a very high fat content, so they oxidize and become rancid very quickly at room temperature and will need to be thrown away.