question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

oncreate and conditionals

See original GitHub issue

if i’m doing that:

const Panel = (prop, children) => (
  <section oncreate={element => console.log('created', prop.id)}>
    {children}
    {prop.current && ' (active)'}
  </section>
)

const state = {
  panels: Array.from(new Array(10), (val, index) => index + 1),
  currentPanel: 1
}

const actions = {
  prevPanel: () => state => ({
    currentPanel: state.currentPanel > 0 ? state.currentPanel - 1 : 0
  }),
  nextPanel: () => state => ({
    currentPanel: state.currentPanel < state.panels.length - 1 ? state.currentPanel + 1 : state.panels.length - 1
  })
}

const view = (state, actions) => (
  <div>
      <button onclick={actions.prevPanel}>
          Prev
        </button>
        <button onclick={actions.nextPanel}>
          Next
        </button>

      <div>
        {state.panels.map((v, i) => (
          <Panel id={i} current={i === state.currentPanel}>
            This is Panel {v}
          </Panel>
        ))}
      </div>
  </div>
)

app(state, actions, view, root)

everything works as expected and i get a couple of “created x” at my console log

but if i’m changing to this, to render only the active panel:

const Panel = (prop, children) =>
  prop.current && (
    <section oncreate={element => console.log('created', prop.id)}>
      {children}
    </section>
  )

now i get one console log for the first element, then if i change state.currentPanel the app works as expected but without triggering the oncreate… so no further console line!

any ideas?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mietennetcommented, Dec 22, 2017

ok, thanks again!

great work, guys

0reactions
zacenocommented, Dec 22, 2017

It’s one of those things that’s less confusing if you’re not using JSX

Read more comments on GitHub >

github_iconTop Results From Across the Web

What do you write in conditionals when there are doubles
What do you write in conditionals when there are doubles ... onCreate(savedInstanceState); setContentView(R.layout.activity_kalkulator); ...
Read more >
Conditional navigation - Android Developers
When designing navigation for your app, you might want to navigate to one destination versus another based on conditional logic.
Read more >
Functions in Android (1 hour) - Hack Pacific (@hackpacific)
... Variables: Exercises (1 hour) · Conditionals (2 hours) · Conditionals: Exercises (1 hour) ... onCreate looks a lot like functions we've seen...
Read more >
Android Tutorial for Beginners 6 # Android Activity Lifecycle ...
(onStop) □ If it is garbage collected (onDestroy) Android Activity Life Cycle Lifetime: onCreate () to onDestroy() Visible when: onStart() ...
Read more >
Class Components | Marko
In this case, the component may define a second component class to use the onCreate , onInput , and onRender lifecycle methods.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found