4.4.6 • Published 7 months ago

@phygrid/signals-react v4.4.6

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
7 months ago

@phygrid/signals-react

A React library for integrating Phygrid Signals into your react applications.

Installation

Use either yarn or npm to install the package:

# Using yarn
yarn install @phygrid/signals-react

# Using npm
npm install @phygrid/signals-react

Usage

Basic Integration

The simplest way to integrate Signals into your React application is using the useGridSignals hook:

import React, { useEffect } from 'react';
import './App.css';
import { useGridSignals } from "@phygrid/signals-react";

function App() {
  const { isReady, signalsService } = useGridSignals();
  
  useEffect(() => {
    if (isReady) {
      // Example of sending an event
      signalsService.sendEvent(...);
    }
  }, [isReady, signalsService]);

  return (
    <div className="App">
      <p>Hello Signals</p>
    </div>
  );
}

export default App;

Custom Parameters

For more control, you can initialize the signals service with custom parameters using the useGridSignalsWithExternalParams hook:

import React, { useEffect } from 'react';
import './App.css';
import { useGridSignalsWithExternalParams } from "@phygrid/signals-react";

function App() {
  const initParams = {
    "deviceId": "device-12345",
    "installationId": "install-67890",
    "spaceId": "space-abcdef",
    "tenantId": "tenant-xyz",
    "appVersion": "1.0.0",
    "appId": "com.example.app",
    "environment": "production",
    "dataResidency": "EU",
    "country": "SE",
    "installationVersion": "2.3.4",
    "accessToken": "eyJhbGciOiJIUzI1NiIsInR...",
    "clientUserAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
    "ip": "192.168.1.100"
  };
  
  const { isReady, signalsService } = useGridSignalsWithExternalParams(initParams);
  
  useEffect(() => {
    if (isReady) {
      // Example of sending an event
      signalsService.sendEvent(...);
    }
  }, [isReady, signalsService]);

  return (
    <div className="App">
      <p>Hello Signals</p>
    </div>
  );
}

export default App;

API Reference

Hooks

useGridSignals()

Initializes the signals service with default parameters.

Returns:

  • isReady (boolean): Indicates whether the signals service is initialized and ready to use
  • signalsService (object): The signals service instance for sending events

useGridSignalsWithExternalParams(initParams)

Initializes the signals service with custom parameters.

Parameters:

  • initParams (object): Configuration object with the following properties:
    • deviceId (string): Unique identifier for the device
    • installationId (string): Unique identifier for the installation
    • spaceId (string): Identifier for the space
    • tenantId (string): Identifier for the tenant
    • appVersion (string): Version of the application
    • appId (string): Identifier for the application
    • environment (string): Environment (e.g., "production", "development")
    • dataResidency (string): Location for data residency
    • country (string): Country code
    • installationVersion (string): Version of the installation
    • accessToken (string): JWT or other access token
    • clientUserAgent (string): User agent string
    • ip (string): IP address

Returns:

  • isReady (boolean): Indicates whether the signals service is initialized and ready to use
  • signalsService (object): The signals service instance for sending events

Available Methods

Complete details regarding the available methods in signalsService can be found in here


Troubleshooting

If you find any errors when importing the package, make sure that 1. config-overrides.js is setup properly, an example is given below:

const webpack = require('webpack');
const path = require('path');

module.exports = function override(config, env) {
  config.module.rules.push({
    test: /\.(ts|tsx)$/,
    loader: 'ts-loader',
    options: {
      transpileOnly: true,
      compilerOptions: {
        module: 'esnext',
        moduleResolution: 'node',
      },
    },
    exclude: /node_modules/,
  });

  delete config.externals;

  config.plugins.push(
    new webpack.IgnorePlugin({ resourceRegExp: /^https-proxy-agent$/ }),
    new webpack.IgnorePlugin({ resourceRegExp: /^http-proxy-agent$/ })
  );

  config.resolve.fallback = {
    assert: require.resolve('assert/'),
    buffer: require.resolve('buffer/'),
    stream: require.resolve('stream-browserify'),
    util: require.resolve('util/'),
    net: false,
    tls: false,
    fs: false,
    child_process: false,
    http: false,
    https: false,
    os: false,
    url: false,
  };

  config.module.rules.push({
    test: /abort-controller/,
    resolve: { fullySpecified: false },
  });

  config.resolve.alias = {
    ...config.resolve.alias,
    'react': path.resolve('./node_modules/react'),
    'react-dom': path.resolve('./node_modules/react-dom')
  };

  return config;
};
  1. Make sure that your webpack.config.js is setup properly, for example:
const webpack = require('webpack');
const path = require('path');

module.exports = function override(config, env) {
  // Add React resolution alias
  config.resolve.alias = {
    ...config.resolve.alias,
    'react': path.resolve('./node_modules/react'),
    'react-dom': path.resolve('./node_modules/react-dom')
  };

  // Add externals configuration
  config.externals = {
    ...config.externals,
    react: 'React',
    'react-dom': 'ReactDOM'
  };

  // Existing fallbacks for node.js core modules
  config.resolve.fallback = {
    http: require.resolve('stream-http'),
    https: require.resolve('https-browserify'),
    stream: require.resolve('stream-browserify'),
    util: require.resolve('util/'),
    os: require.resolve('os-browserify/browser'),
    assert: require.resolve('assert/'),
    net: false,
    tls: false,
  };
  
  config.plugins.push(
    new webpack.ProvidePlugin({
      process: 'process/browser',
      Buffer: ['buffer', 'Buffer'],
    })
  );
  
  return config;
};
  1. If you are using typescript, make sure you have tsconfig.json setup properly, for example:
{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react",
    "baseUrl": "src"
  },
  "include": [
    "src"
  ]
}
  1. For react version related issues, make sure you add following in your package.json file:
{
  "resolutions": {
      "react": "^18.0.0",
      "react-dom": "^18.0.0"
    },
}
4.2.219

11 months ago

4.2.459

9 months ago

4.2.338

11 months ago

4.2.217

11 months ago

4.2.339

11 months ago

4.2.457

9 months ago

4.2.336

11 months ago

4.2.458

9 months ago

4.2.337

11 months ago

4.2.216

11 months ago

4.2.466

8 months ago

4.2.345

11 months ago

4.2.224

11 months ago

4.2.467

8 months ago

4.2.346

11 months ago

4.2.225

11 months ago

4.2.464

9 months ago

4.2.343

11 months ago

4.2.222

11 months ago

4.2.465

9 months ago

4.2.344

11 months ago

4.2.223

11 months ago

4.2.462

9 months ago

4.2.341

11 months ago

4.2.220

11 months ago

4.2.463

9 months ago

4.2.342

11 months ago

4.2.221

11 months ago

4.2.460

9 months ago

4.2.461

9 months ago

4.2.340

11 months ago

4.2.329

11 months ago

4.2.448

9 months ago

4.2.327

11 months ago

4.2.449

9 months ago

4.2.328

11 months ago

4.2.446

9 months ago

4.2.325

11 months ago

4.2.447

9 months ago

4.2.326

11 months ago

4.0.1

12 months ago

4.2.455

9 months ago

4.2.334

11 months ago

4.2.456

9 months ago

4.2.335

11 months ago

4.2.453

9 months ago

4.2.332

11 months ago

4.2.454

9 months ago

4.2.333

11 months ago

4.2.212

11 months ago

4.2.451

9 months ago

4.2.330

11 months ago

4.2.452

9 months ago

4.2.331

11 months ago

4.2.450

9 months ago

4.2.439

9 months ago

4.2.318

11 months ago

4.2.319

11 months ago

4.2.437

9 months ago

4.2.316

11 months ago

4.2.438

9 months ago

4.2.317

11 months ago

4.2.435

9 months ago

4.2.314

11 months ago

4.2.436

9 months ago

4.2.315

11 months ago

4.2.444

9 months ago

4.2.323

11 months ago

4.2.324

11 months ago

4.2.442

9 months ago

4.2.321

11 months ago

4.2.443

9 months ago

4.2.322

11 months ago

4.2.440

9 months ago

4.2.441

9 months ago

4.2.320

11 months ago

4.2.309

11 months ago

4.2.428

9 months ago

4.2.307

11 months ago

4.3.7-dev

8 months ago

4.2.429

9 months ago

4.2.308

11 months ago

4.2.426

9 months ago

4.2.305

11 months ago

4.2.427

9 months ago

4.2.306

11 months ago

4.2.424

9 months ago

4.2.303

11 months ago

4.2.425

9 months ago

4.2.304

11 months ago

4.2.433

9 months ago

4.2.312

11 months ago

4.2.313

11 months ago

4.2.431

9 months ago

4.2.310

11 months ago

4.2.432

9 months ago

4.2.311

11 months ago

4.2.430

9 months ago

4.2.419

10 months ago

4.2.417

10 months ago

4.2.418

10 months ago

4.2.415

10 months ago

4.2.416

10 months ago

4.2.413

10 months ago

4.2.414

10 months ago

4.2.301

11 months ago

4.2.423

9 months ago

4.2.302

11 months ago

4.2.420

10 months ago

4.2.300

11 months ago

4.2.408

10 months ago

4.2.409

10 months ago

4.2.406

10 months ago

4.2.407

10 months ago

4.2.404

10 months ago

4.2.405

10 months ago

4.2.402

10 months ago

4.2.403

10 months ago

4.2.411

10 months ago

4.2.412

10 months ago

4.2.410

10 months ago

4.2.401

10 months ago

4.3.6-dev

8 months ago

4.3.5-dev

8 months ago

4.4.1

8 months ago

4.4.0

8 months ago

2.0.49

1 year ago

4.4.3

7 months ago

4.4.2

7 months ago

4.4.5

7 months ago

4.4.4

7 months ago

4.4.6

7 months ago

2.0.57

1 year ago

2.0.58

1 year ago

2.0.55

1 year ago

2.0.56

1 year ago

2.0.53

1 year ago

2.0.54

1 year ago

2.0.51

1 year ago

2.0.52

1 year ago

2.0.50

1 year ago

2.0.68

1 year ago

2.0.69

1 year ago

2.0.66

1 year ago

2.0.67

1 year ago

2.0.64

1 year ago

2.0.65

1 year ago

2.0.63

1 year ago

2.0.60

1 year ago

2.0.79

1 year ago

4.3.4-dev

8 months ago

2.0.77

1 year ago

2.0.78

1 year ago

2.0.75

1 year ago

2.0.76

1 year ago

2.0.73

1 year ago

2.0.74

1 year ago

2.0.71

1 year ago

2.0.72

1 year ago

2.0.70

1 year ago

2.0.88

1 year ago

2.0.89

1 year ago

2.0.86

1 year ago

2.0.87

1 year ago

2.0.84

1 year ago

2.0.85

1 year ago

2.0.82

1 year ago

2.0.83

1 year ago

2.0.80

1 year ago

2.0.81

1 year ago

2.0.99

12 months ago

2.0.97

12 months ago

2.0.98

12 months ago

2.0.95

12 months ago

2.0.96

12 months ago

2.0.93

1 year ago

2.0.94

12 months ago

2.0.91

1 year ago

2.0.92

1 year ago

2.0.90

1 year ago

4.3.3-dev

8 months ago

4.3.2-dev

8 months ago

2.0.151

12 months ago

2.0.150

12 months ago

2.0.139

12 months ago

2.0.138

12 months ago

2.0.137

12 months ago

2.0.136

12 months ago

2.0.135

12 months ago

2.0.134

12 months ago

2.0.133

12 months ago

2.0.132

12 months ago

2.0.131

12 months ago

2.0.130

12 months ago

4.2.293

11 months ago

4.2.294

11 months ago

4.2.291

11 months ago

4.2.292

11 months ago

2.0.149

12 months ago

2.0.148

12 months ago

4.2.290

11 months ago

2.0.147

12 months ago

2.0.146

12 months ago

2.0.145

12 months ago

2.0.144

12 months ago

2.0.143

12 months ago

4.2.299

11 months ago

2.0.142

12 months ago

2.0.141

12 months ago

4.2.297

11 months ago

2.0.140

12 months ago

4.2.298

11 months ago

4.2.295

11 months ago

4.2.296

11 months ago

4.3.9-dev

8 months ago

4.3.0-dev

8 months ago

2.0.109

12 months ago

4.2.282

11 months ago

2.0.119

12 months ago

4.2.283

11 months ago

2.0.118

12 months ago

4.2.280

11 months ago

2.0.117

12 months ago

4.2.281

11 months ago

2.0.116

12 months ago

2.0.115

12 months ago

2.0.114

12 months ago

2.0.113

12 months ago

2.0.112

12 months ago

2.0.111

12 months ago

2.0.110

12 months ago

4.2.288

11 months ago

4.2.289

11 months ago

4.2.286

11 months ago

4.2.287

11 months ago

4.2.284

11 months ago

4.2.285

11 months ago

4.2.392

10 months ago

4.2.271

11 months ago

4.2.393

10 months ago

4.2.272

11 months ago

2.0.129

12 months ago

4.2.390

10 months ago

2.0.128

12 months ago

4.2.391

10 months ago

4.2.270

11 months ago

2.0.127

12 months ago

2.0.126

12 months ago

2.0.125

12 months ago

2.0.124

12 months ago

2.0.123

12 months ago

4.2.279

11 months ago

2.0.122

12 months ago

2.0.121

12 months ago

4.2.398

10 months ago

4.2.277

11 months ago

2.0.120

12 months ago

4.2.399

10 months ago

4.2.278

11 months ago

4.2.396

10 months ago

4.2.275

11 months ago

4.2.397

10 months ago

4.2.276

11 months ago

4.2.394

10 months ago

4.2.273

11 months ago

4.2.395

10 months ago

4.2.274

11 months ago

4.2.259

11 months ago

4.2.381

11 months ago

4.2.260

11 months ago

4.2.261

11 months ago

4.2.380

11 months ago

4.2.389

10 months ago

4.2.268

11 months ago

4.2.269

11 months ago

4.2.387

10 months ago

4.2.266

11 months ago

4.2.388

10 months ago

4.2.267

11 months ago

4.2.264

11 months ago

4.2.386

10 months ago

4.2.265

11 months ago

4.2.383

10 months ago

4.2.262

11 months ago

4.2.263

11 months ago

4.2.248

11 months ago

4.2.249

11 months ago

2.0.108

12 months ago

4.2.371

11 months ago

4.2.250

11 months ago

2.0.107

12 months ago

2.0.106

12 months ago

2.0.105

12 months ago

2.0.104

12 months ago

2.0.103

12 months ago

2.0.102

12 months ago

2.0.101

12 months ago

4.2.257

11 months ago

2.0.100

12 months ago

4.2.379

11 months ago

4.2.258

11 months ago

4.2.255

11 months ago

4.2.256

11 months ago

4.2.253

11 months ago

4.2.254

11 months ago

4.2.372

11 months ago

4.2.251

11 months ago

4.2.252

11 months ago

4.2.239

11 months ago

4.2.358

11 months ago

4.2.237

11 months ago

4.2.359

11 months ago

4.2.238

11 months ago

4.3.8-dev

8 months ago

4.2.360

11 months ago

4.2.246

11 months ago

4.2.247

11 months ago

4.2.244

11 months ago

4.2.245

11 months ago

4.2.363

11 months ago

4.2.242

11 months ago

4.2.364

11 months ago

4.2.243

11 months ago

4.2.361

11 months ago

4.2.240

11 months ago

4.2.362

11 months ago

4.2.241

11 months ago

4.2.349

11 months ago

4.2.228

11 months ago

4.2.229

11 months ago

4.2.468

8 months ago

4.2.347

11 months ago

4.2.226

11 months ago

4.2.469

8 months ago

4.2.348

11 months ago

4.2.227

11 months ago

4.2.470

8 months ago

4.2.356

11 months ago

4.2.235

11 months ago

4.2.357

11 months ago

4.2.236

11 months ago

4.2.354

11 months ago

4.2.233

11 months ago

4.2.355

11 months ago

4.2.234

11 months ago

4.2.473

8 months ago

4.2.352

11 months ago

4.2.231

11 months ago

4.2.353

11 months ago

4.2.232

11 months ago

4.2.471

8 months ago

4.2.350

11 months ago

4.2.472

8 months ago

4.2.351

11 months ago

4.2.230

11 months ago

2.0.48

1 year ago

2.0.47

1 year ago

2.0.46

1 year ago

2.0.45

1 year ago

2.0.44

1 year ago

2.0.42

1 year ago

2.0.41

1 year ago

2.0.40

2 years ago

2.0.39

2 years ago

2.0.38

2 years ago

2.0.37

2 years ago

2.0.36

2 years ago

2.0.35

2 years ago

2.0.34

2 years ago

2.0.33

2 years ago

2.0.32

2 years ago

2.0.31

2 years ago

2.0.30

2 years ago

2.0.29

2 years ago

2.0.28

2 years ago

2.0.27

2 years ago

2.0.26

2 years ago

2.0.24

2 years ago

2.0.7

2 years ago

2.0.3

2 years ago

2.0.0

2 years ago

1.0.0

2 years ago

0.2.0

2 years ago

0.1.18

2 years ago

0.1.16

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago