render() {
const isLoggedIn = this.state.isLoggedIn;
return (
<div>
The user is <b>{isLoggedIn ? 'currently' : 'not'}</b> logged in. </div>
);
}
render() {
const isLoggedIn = this.state.isLoggedIn;
return (
<div>
{isLoggedIn ? <LogoutButton onClick={this.handleLogoutClick} />
: <LoginButton onClick={this.handleLoginClick} /> }
</div> );
}
In <TodoItem />
you can similar logic for modifing todo text as you use in <AddTodo />
for creating new todo. I use conditional rendering to render the <TextInput />
when isEditing
is true
, and <Text />
when it's not.
{isEditing
? <TextInput value={text} onChangeText={setText} style={styles.itemText} />
: <Text style={styles.itemText}>{props.title}</Text>
}
We can then use conditional rendering to display the term or definition for each card.
{c.flipped ? c.definition : c.term}
Recommend
React Conditional Rendering Inline If with Logical && Operator
React Conditional Rendering Element Variables
React Composition vs Inheritance Specialization
React Composition vs Inheritance Containment
React Using the State Hook Recap Tip: Using Multiple State Variables
React Using the State Hook Recap Tip: What Do Square Brackets Mean?
React Using the State Hook Recap
React Using the State Hook Updating State
React Using the State Hook Reading State
React Using the State Hook Declaring a State Variable
React Using the State Hook What’s a Hook?
React Using the State Hook Hooks and Function Components
React Using the State Hook Equivalent Class Example
React Handling Events Passing Arguments to Event Handlers
React Rules of Hooks Explanation
React Rules of Hooks ESLint Plugin
ReactDOMServer Reference renderToStaticNodeStream()
ReactDOMServer Reference renderToNodeStream()
ReactDOMServer Reference renderToStaticMarkup()
ReactDOMServer Reference renderToString()
React Testing Recipes Multiple Renderers
React Testing Recipes Snapshot Testing
React Testing Recipes Mocking Modules
React Testing Recipes Data Fetching
React Testing Recipes Rendering
React Testing Recipes Setup/Teardown
React Rendering Elements Updating the Rendered Element
React Rendering Elements Rendering an Element into the DOM
React Component State What is the difference between passing an object or a function in setState?
React Component State Why is setState giving me the wrong value?
React Refs and the DOM Callback Refs
React Refs and the DOM Accessing Refs Refs and Function Components
React Refs and the DOM Accessing Refs Adding a Ref to a Class Component
React Refs and the DOM Accessing Refs Adding a Ref to a DOM Element
React Refs and the DOM Accessing Refs
React Refs and the DOM Creating Refs
File Structure Is there a recommended way to structure React projects? Grouping by file type
Glossary of React Terms Components props.children
Glossary of React Terms Components props
Glossary of React Terms Components
Glossary of React Terms Elements
React Code-Splitting Named Exports
React Code-Splitting Route-based code splitting