Skip to Main Content
ASP.NET Core 3 and React
book

ASP.NET Core 3 and React

by Carl Rippon
December 2019
Intermediate to advanced content levelIntermediate to advanced
598 pages
12h 21m
English
Packt Publishing
Content preview from ASP.NET Core 3 and React

Optional and default props

A prop can be optional so that the consumer doesn't necessarily have to pass it into a component. For example, we could have an optional prop in the Question component that allows a consumer to change whether the content of the question is rendered or not. We'll do this now:

  1. First, let's import the gray2 color from our global styles into Question.tsx:
import { gray2, gray3 } from './Styles';
  1. We need to add the content into the Question component, so add the following code beneath the question title in the JSX:
export const Question: FC<Props> = ({ data }) => (  <div ... >    <div ... >      {data.title}    </div>    <div      css={css`        padding-bottom: 10px;        font-size: 15px;        color: ${gray2};      `}    >      {data.content.length > 50 ? `${data.content.substring(0, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

ASP.NET Core 5 and React - Second Edition

ASP.NET Core 5 and React - Second Edition

Carl Rippon
ASP.NET Core 5 for Beginners

ASP.NET Core 5 for Beginners

Andreas Helland, Vincent Maverick Durano, Jeffrey Chilberto, Ed Price

Publisher Resources

ISBN: 9781789950229Supplemental Content