0

I know there's similar thread already but i'm a total newbie and i can't work it. I'm not able include conditional rendering after my map function, do i need some sortf of HTML-tag inbetween?

     const renderTableData = () => { 
    let id = 1;
    const activeButton = () => { 
    
    }
    return (
      <tr>
        {days.map((val) => (
            <td>
                 {timeSlot.map((n, i) => ( 
                    
                //     if(freeSlotsList.includes(id)){     THIS CODE SNIPPET
               //         return (<h1>Testing</h1>           DON'T WORK
              //          )}
                    
                 
              <button id={id++} className={activeButton}> {n} {id}</button> 
                 ))}
            </td>
        ))}
      </tr>
    );
  };

EDIT:

i can't seem to access my freeSlotsList, it looks like this

const [freeSlotsList, setFreeSlotsList] = useState([])

useEffect(() => {
Axios.post('http://localhost:3001/api/get/week1/ex').then((response) => {
    setFreeSlotsList(response.data)

    
  })
}, [])
  

1 Answer 1

1

Try this, You need to wrap your code into {} if you want to write js code. As () will simply return that as jsx.

const renderTableData = () => { 
let id = 1;
const activeButton = () => { 

}
return (
  <tr>
    {days.map((val) => (
        <td>
             {timeSlot.map((n, i) => {
                
                 if(freeSlotsList.includes(id)){     
                    return (<h1>Testing</h1>         
                    )}
                
             
          return <button id={id++} className={activeButton}> {n} {id}</button> 
             )}}
        </td>
    ))}
  </tr>
);
};
Sign up to request clarification or add additional context in comments.

9 Comments

That's probably it! altough i can't display my button this way. Is there any way to circumvent that?
Probably there is some mismatch in closing brackets. And please wrap button in ( ).
Ahh i found it, was )}} when it should've been })}.
I still can't access timeSlot a useState([]) inside the function, do you have any clue as to why?
How timeSlot is being set? I guess you are referring wrong variable. Or add more description for that.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.