@izzythepush,
The same book pointed out that, back in the caveman days, people had to make quick decisions to ensure survival. As you pointed out - identity as friend or foe was necessary, so societies made themselves distinct.
But, the book went further to say that in caveman days we had to simplify things - that we couldn't be hamstrung by indecision, so we didn't dig below the surface...we relied on our instinct/feelings to assess the situation, and acted. Then as society formed rules, a quick check on the surface rules (and maybe consequences), then acted...and so on as society got more complicated. But further - that as society got more complicated, those that survived were able to act instantly by filtering out/ignore things that didn't agree with their mindset (ie. avoiding complications that resulted in inaction) .
Basically, the book was also suggesting that our brains are genetically driven to filter out anything that doesn't agree with what we already 'know' or 'believe'.
This is why humans don't behave logically. As relates to this forum - it is why some avoid like the plague contradictory evidence. It is why we go to great, convoluted lengths to avoid contradiction in their beliefs as opposed to the world out there. It is why humans actually don't like seeing perspectives that are 'from their enemies eyes' etc. Or why, once a person starts seeing conspiracies - they start seeing them everywhere, etc.
But as relates to racism - it is also why it is very difficult to dislodge the 'we're superior', or 'that race is <label> type of ideas.
Strangely - adding your post and mine together - it makes me think that yes, race is illusory, but I don't think we as the human race, will ever truly accept it.