Skip to content

show element if it has items in render function #997

Answered by akeni
akeni asked this question in Q&A
Discussion options

You must be logged in to vote

okay I have figured out a way to do it:

we can get the collection through render by checking the state collection and seeing if there are items in the source.

sorry the github code display is buggy due to html escape using `

render({elements, render, html, state}, root) {
    const source = 'element1';
    const hasElement = state.collections.filter(({source}) => source.indexOf(source.sourceId) >= 0).reduce((prev, curr) => prev + curr.items.length, 0) > 0;

    render(
        html`${hasElement && ( html`<div>${element1}</div>`)}, 
       root
    )
}

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@akeni
Comment options

Comment options

You must be logged in to vote
1 reply
@Haroenv
Comment options

Answer selected by akeni
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants