Ad
Problems With Ternary Operator In ReactJS
I'm trying to use a ternary operator to show my loading state in reactJSm but i'dont understand why its always true, i'm using reactotron to debug my state and its working correctly "onload: loading true, after :loading false. But when i use the operator its always true. Someone could help me ?
i tried use the loading={loading ? 1 : 0} inside Container but nothing change...
<Container>
<Content>
<header>
<p>Meus Meetups</p>
<button type="button">Novo Meetup</button>
</header>
<ul>
{loading ? (
<AiOutlineLoading color="#eb3443" size={40} />
) : (
meetups.map(meetup => (
<MeetList key={meetup.id}>
<Link to={`/details/${meetup.id}`}>
<strong>{meetup.title}</strong>
<p>
{format(parseISO(meetup.date), `dd 'de' MMMM 'às' HH'h'`, {
locale: pt,
})}
</p>
</Link>
</MeetList>
))
)}
</ul>
</Content>
</Container>
Ad
Answer
Operator looks fine. Are you sure that loading state has a vaild value? Try changing the loading to hardcoded false value to verify that operator is fine.
Ad
source: stackoverflow.com
Related Questions
- → Import statement and Babel
- → should I choose reactjs+f7 or f7+vue.js?
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → .tsx webpack compile fails: Unexpected token <
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → React Native with visual studio 2015 IDE
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
- → How do I determine if a new ReactJS session and/or Browser session has started?
- → Alt @decorators in React-Native
- → How to dynamically add class to parent div of focused input field?
Ad