Content not rendering in conditional statement

Content not rendering in conditional statement



So currently i have a react component. I have declared an array which contains a series of objects for some sample data. As the initial state for 'currentStep' is 0, I expect the <div>Screen 1</div> to render, however, all i get is a blank screen.


<div>Screen 1</div>



Any ideas?


import React, Component from 'react';

/**
* sample data to pass through
*/

const contents =
[
title: 'First Screen', step: 0, children: <div>Screen 1</div> ,
title: 'Second Screen', step: 1, children: <div>Screen 2</div> ,
title: 'Third Screen', step: 2, children: <div>Screen 3</div> ,
];

class Wizard extends Component
state =
currentStep: 0,


Content = () =>
const currentStep = this.state;
contents.map((content) =>
if (content.step === currentStep) return content.children;
return null;
);


render()
return (
<div>this.Content()</div>
);



export default Wizard;






did you try to console.log(this.Content()) ? Any error messages in the console ?

– Dinosan0908
Sep 6 '18 at 14:28




2 Answers
2



You need to return your map in Content. Right now you are returning nothing. For ex:


Content = () =>
const currentStep = this.state;
return contents.map((content) =>
if (content.step === currentStep) return content.children;
return null;
);



Your Content function isn't actually returning anything, but your map function is. If you return contents.map(...), then you should get what you are expecting.


Content


return contents.map(...)






added return infront of contents.map, now it works :D

– Mubeen Hussain
Sep 6 '18 at 14:29



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)