There were a lot of people in a state of despair after the 2016 election.

Donald Trump, after running a campaign that was accused of dipping into racist tendencies, was elected president of the United States, and the idea that we were living in a “post-racial” period of American history, one that just elected its first African American president, became a dream deferred, or forgotten.

The comparatively sane time of Barack Obama and his message of “hope” was over, but not for writer Andrew Shaffer. He channeled the nation’s sadness into a bizarre but compelling 2018 novel called “Hope Never Dies,” which recast Obama and Vice President Joe Biden as pulp detectives out to solve a mystery. The cover featured an illustration of the pair in a vintage T-top Trans Am, with Biden behind the wheel and Obama standing up, pointing onward.

It’s the sort of book that could have been a one-note joke that stopped being funny before it was even done being told, but Shaffer managed to craft a compelling tale of adventure as well as an unblinking look at the mixed record of the former bromantic duo in power. It became a New York Times best-seller.

Now Shaffer is back with the sequel, “Hope Rides Again.” We got a chance to chat with Shaffer ahead of his Bay Area appearances Friday, Aug. 2, at Books Inc. in Campbell, and Saturday, Aug. 3, at Book Passage at the Ferry Building. The Kentucky writer talked about the weird world of real-life fan fiction and why his Obama/Biden mysteries can’t be written without some disappointment.

Question: What possessed you to take Barack Obama and Joe Biden and turn them into larger-than-life action heroes?

Answer: My original inspiration was this photo of Joe Biden a couple of years ago that had him staring out of some window with his aviators on, and he looked kind of forlorn. The joke has always been that vice presidents don’t have anything to do while they’re in office. I thought it would be fun if he sort of had a Walter Mitty-like inner life going on where he was a detective or private agent or something, solving crimes around the White House or around the world. It wasn’t until they were almost out of office and the memes were going around about Obama/Biden being best friends that I realized I needed a foil for Biden. It just happened at the right time. I don’t think people realized what they had for eight years.

Q: How do people respond to this alternative universe you’ve created? Does it give people hope or make them sad for what’s gone?

A: In 2016, I wrote a book called “Day of the Donald,” and this is when Trump was still a candidate no one thought was going to win. I thought, “What if I just write a satire about a world where he becomes president like when Lex Luthor did in the comics?” Then slowly I watched it actually happen, and I saw that a satire doesn’t necessarily give anybody hope. I wanted something that did after that.

With “Hope Never Dies” and “Hope Rides Again,” I’ve found that with people reading them you sort of see how people are coping in this new world. It’s still a fantasy world, but it does seem to give them hope.

Q: But you don’t shy away from the disappointments and the sadness. There are real downers in “Hope Never Dies.”

A: As I was turning chapters in to my editor, I warned him there were downers and expected pushback on that. Instead they told me people in the office actually started tearing up. I think with a mystery or thriller, you need the ups and downs. “Lethal Weapon” starts with Mel Gibson contemplating suicide. The ones that stick with you have a narrative arc. Otherwise it would be a one-note joke.

Q: With the current climate, are you ever tempted to take the books too far, change your created world for the better? Do you want to play God at that level?

A: No. There are instances where I want to say more and I hint at it. There’s a bit in the new book where they talk about street violence and someone brings up mass incarceration and the effect on African American communities. Joe has sort of a bitter rumination, and it works because the reader knows Biden was the architect of a lot of crime bills in the ’90s. I don’t want to ignore the reality, but on the other hand, these are supposed to be beach reads. I only use the word “Trump” once or twice. It’s supposed to make you miss the days when a week could go by without you knowing what the president said about anything because they were off doing their job while you do yours.

Q: Striving through normalcy the long way through absurdity?

A: Exactly.

Q: Thanks to “Euphoria,” there’s a new discussion about fan fiction that involves actual people. HBO sort of got in trouble by animating a fan-fiction sex scene between two members of a real-life boy band. Are you ever worried about the effects of this stuff or where it will go?

A: You know, I did have someone on Twitter yell at me that, “They should stay out of detective works and stick to politics where they belong.” There are some people with a tenuous grip on reality, but most people who read the book know the difference between the real world and the fictional one. At least I hope they do.

Politicians are different. A couple of friends of mine wrote “Taylor Swift: Girl Detective” but had a hard time finding publishers because no one wanted to do that without permission. These are clearly covered under satire and public domain, but I stay away from their families for the most part. It’s a really respectful portrayal.

Andrew Shaffer author appearances: Talking about his new book “Hope Rides Again.” 7 p.m. Friday, Aug. 2. Books Inc., 1875 S. Bascom Ave. #600, Campbell. Free. (408) 378-2726. Booksinc.net

2 p.m. Saturday, Aug.3. Book Passage, 1 Ferry Building Suite 42, San Francisco. Free. 415-835-1020. Bookpassage.com