Skip to content

Instantly share code, notes, and snippets.

@whichsteveyp
Last active February 24, 2017 20:55
Show Gist options
  • Save whichsteveyp/f78e74d3c4329bc913c3bd506d64b3e8 to your computer and use it in GitHub Desktop.
Save whichsteveyp/f78e74d3c4329bc913c3bd506d64b3e8 to your computer and use it in GitHub Desktop.
const API = ({ match, data }) => {
// this i left as is
const { params: { mod, header, environment } } = match;
const doc = data.api.find(doc => mod === doc.title.slug);
// don't mind the tern here as much, maybe would split the find to its own `validDocHeaderMatch`
const validHeader = doc && (header ? !!doc.headers.find(h => h.slug === header) : true );
// this is my 😍 for conditional JSX thus far
return <Block>
{!doc && <Redirect to={`/${environment}`}/>}
{(doc && !validHeader) && <Redirect to={`/${enviroment}/api/${mod}`}/>}
{(doc && validHeader) && <MarkdownViewer html={doc.markup}/>}
</Block>;
};
@vinodkl
Copy link

vinodkl commented Feb 24, 2017

line 12: sometimes when the values are null, this resolves to 0 and displays in the UI as 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment