Meteor React - Session best practices

I would think it should be almost as easy to create a useTracker hook as useSession since they are both Meteor reactive.

1 Like

There are a couple proposals for userTracker and the like:


Didn’t see them mentioned anywhere yet. Both look quite interesting!

I’d really like to see react-meteor-data package get more love!

1 Like

I’m on Meteor 1.8 and Blaze. I’m in the process of converting my Blaze codebase over to React 16.8 (using only the functional approach with Hooks).

The follow is an example of how I’m using Tracker (using https://github.com/meteor/react-packages/tree/devel/packages/react-meteor-data). My question is, instead of using the the HOC approach here, is their a way to use a Hooks approach?

Also, what are the current patterns for using React with Meteor + client state that NO NOT involve using yet another 3rd party library (I don’t want to take on new dependencies if I can avoid it).

<template name="BlazeComponentExample">
  <nav>
    {{> React component=ReactComponentExample }}
  </nav>
</template>
import ReactComponentExample from './react-component-example';

Template.BlazeComponentExample.helpers({
	ReactComponentExample() {
		return ReactComponentExample || null;
	}
});
import React from 'react';
import { withTracker } from 'meteor/react-meteor-data';
import SidebarNavigation from '../sidebar/sidebar-navigation';
import { statusState, iconState } from '../navbar-helpers';

const ReactComponentExample = ({ mode }) => {
  ...

  return (  
    <ul>
      <li>
        <SidebarNavigation mode={mode} />
      </li>
    </ul>
  );
}

export default withTracker(() => {
  const handle = Meteor.subscribe('userAccount', Meteor.userId());
  const { accountMode } = accounts.findOne({ userId: Meteor.userId() }) || '';

  return {
    loading: !handle.ready(),
    mode: accountMode ? accountMode : ''
  }
})(ReactComponentExample);
1 Like