DEV Community

Discussion on: Simplify condition rendering in React.js

Collapse
 
chrisczopp profile image
chris-czopp

Nice one! If you're interested in exploring other frameworks, in SolidJS you have:

function Show<T>(props: {
  when: T | undefined | null | false;
  fallback?: JSX.Element;
  children: JSX.Element | ((item: T) => JSX.Element);
}): () => JSX.Element;
Enter fullscreen mode Exit fullscreen mode

...which you can use like:

<Show when={state.count > 0} fallback={<div>Loading...</div>}>
  <div>My Content</div>
</Show>
Enter fullscreen mode Exit fullscreen mode

I find really neat.

Collapse
 
chetan_atrawalkar profile image
Chetan Atrawalkar

How to write this type of code(like second) in Dev Community post please help

Collapse
 
chrisczopp profile image
chris-czopp

Do you mean syntax highlighting? If so, then like this:

Alt Text

It's just Mardown compatible with Github.

Thread Thread
 
chetan_atrawalkar profile image
Chetan Atrawalkar

Yes but how please share image details

Thread Thread
 
rmurati profile image
Redžep Murati

Take a look at this official markdown guide:
markdownguide.org/extended-syntax/

Thread Thread
 
edgarmendozatech profile image
Edgar Mendoza • Edited

@chetan_atrawalkar just surround your code with the following:

Example highlighting

console.log("Hello World");
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
chetan_atrawalkar profile image
Chetan Atrawalkar

Thank you❤️

Collapse
 
rmurati profile image
Redžep Murati

Nice tip. Thank you ❤️

Collapse
 
nemit74180 profile image
nemit74180

hi