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.

returning null in a view

See original GitHub issue

Returning null throws errors, is there a way not to return a root node?

render(vm) {
    return vm.state.bool ? <div>foo</div> : null;
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:22 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
leeoniyacommented, Oct 4, 2018

probably the most ergonomic way to achieve a near-equivalent of a null return is to return a comment node for the view’s root. this means that the view is effectively unmounted and out of the dom, but is still retained by domvm:

var el = domvm.defineElement;
var cm = domvm.defineComment;
var vw = domvm.defineView;
var cv = domvm.createView;

var vis = true;

function AppView(vm) {
  return function() {
    return el("#app", [
      vw(SubView) 
    ]);
  };
}

function SubView() {
  var i = 0;
  
  setInterval(function() {
    i++;
  }, 200);
  
  return function() {
    return vis ? el("div", "abc " + i) : cm("SubView " + i);
  };
}

var vm = cv(AppView).mount(document.body);

setTimeout(function() {
  vis = false;
  vm.redraw();
}, 3000);

setTimeout(function() {
  vis = true;
  vm.redraw();
}, 6000);
1reaction
leeoniyacommented, Aug 9, 2018

ah, ok.

i’ll give this some thought. it’s not a quick fix, but i see how it’s useful and better than create & inject, though i do wonder if that can be made into something similar without modifying the core.

i don’t see anything in https://reacttraining.com/react-router/web/example/basic that can’t be replicated with a bit of js and domvm. this “maintaining view state despite unmounting in a declarative way” seems to be the thorny part.

would be interesting to do a proof of concept with createView, injectView and vm memoization to simulate this. it’s certainly possible, though the ergonomics could be anywhere on the scale from not-too-bad to wtf.

Read more comments on GitHub >

github_iconTop Results From Across the Web

View and paramater is returning null in android kotlin
The onCreateView method is supposed to return the view. You are getting null there because using getView before the view is created cant ......
Read more >
Hibernate runs query against view but returns null values
I'm using MyEclipse 2020.9.16, Spring 4.1 and Hibernate 4.1. I used reverse engineering to generate DAOs and POJOs against an already existing ...
Read more >
Return null values if there is no record for top n selected
I am trying to get the top 'n' rows from the following query: SELECT TOP 1 ImageName FROM (SELECT TOP 5 FROM ClientKeywordMedia...
Read more >
Working with SQL NULL values - SQLShack
The IS NULL condition is used to return rows that contain the NULL values in a column and its syntax is like below: ......
Read more >
ODBC Driver may return NULL value for some fields
If the "soap_response" view is created/modified, then one of the symptoms may be NULL values being returned. Resolution. On an OOB instance, the...
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