## 2.4.2
- Add missing code changes (`cacheOptions` and `lodash`) from 2.4.0.
> This happened due to revert from master that later cleaned changes from dev at merge conflict.
## 2.4.0
- Introduce `useState` and `useEffect`. They should work similarly to the React hooks. Example:
```jsx
const [a, setA] = useState(() => {
console.log("Init 'a'");
return "Y";
});
const [b, setB] = useState("B");
const [sum, setSum] = useState(0);
useEffect(() => {
setSum(a.length + b.length);
return () => {
console.log("cleanup");
};
}, [a, b]);
return (
<div>
A = {a}
<br />B = {b}
<br />
Length sum = {sum}
<div>
<button onClick={() => setA((s) => s + "O")}>A</button>
<button onClick={() => setB(b + "O")}>B</button>
</div>
</div>
);
```
- Add `cacheOptions` optional argument to the following methods:
- `Social.get(keys, blockId|finality, options, cacheOptions)`
- `Social.getr(keys, blockId|finality, options, cacheOptions)`
- `Social.keys(keys, blockId|finality, options, cacheOptions)`
- `Social.index(action, key, options, cacheOptions)`
- `Near.view(contractName, methodName, args, blockId|finality, subscribe, cacheOptions)`
- `Near.block(blockId|finality, subscribe, cacheOptions)`
The `cacheOptions` object is optional and may contain the following property:
- `ignoreCache` - boolean, if true, the method will ignore the cached value in the local DB and fetch the data from the API server. This will only happen once per session. Default is false.
This is useful to avoid loading stale objects that are likely to change often. For example, the index of posts for the main feed, or notifications.
```jsx
const index = Social.index(
"post",
"main",
{
limit: 10,
order: "desc",
},
{
ignoreCache: true,
}
);
```
- Replace `lodash` dependency with `lodash.clonedeep` to reduce bundle size.
- Add `cacheOptions` optional argument to the following methods:
- `Social.get(keys, blockId|finality, options, cacheOptions)`
- `Social.getr(keys, blockId|finality, options, cacheOptions)`
- `Social.keys(keys, blockId|finality, options, cacheOptions)`
- `Social.index(action, key, options, cacheOptions)`
- `Near.view(contractName, methodName, args, blockId|finality, subscribe, cacheOptions)`
- `Near.block(blockId|finality, subscribe, cacheOptions)`
The `cacheOptions` object is optional and may contain the following property:
- `ignoreCache` - boolean, if true, the method will ignore the cached value in the local DB and fetch the data from the API server. This will only happen once per session. Default is false.
This is useful to avoid loading stale objects that are likely to change often. For example, the index of posts for the main feed, or notifications.
```jsx
const index = Social.index(
"post",
"main",
{
limit: 10,
order: "desc",
},
{
ignoreCache: true,
}
);
```
- Add `cacheOptions` optional argument to the following methods:
- `Social.get(keys, blockId|finality, options, cacheOptions)`
- `Social.getr(keys, blockId|finality, options, cacheOptions)`
- `Social.keys(keys, blockId|finality, options, cacheOptions)`
- `Social.index(action, key, options, cacheOptions)`
- `Near.view(contractName, methodName, args, blockId|finality, subscribe, cacheOptions)`
- `Near.block(blockId|finality, subscribe, cacheOptions)`
The `cacheOptions` object is optional and may contain the following property:
- `ignoreCache` - boolean, if true, the method will ignore the cached value in the local DB and fetch the data from the API server. This will only happen once per session. Default is false.
This is useful to avoid loading stale objects that are likely to change often. For example, the index of posts for the main feed, or notifications.
```jsx
const index = Social.index(
"post",
"main",
{
limit: 10,
order: "desc",
},
{
ignoreCache: true,
}
);
```
## 2.3.0
- Expose `encodeURIComponent`, `decodeURIComponent`, `btoa`, `atob`, `isFinite`, `decodeURI` and `encodeURI` in the global scope.
- Refactor native functions into an object, making it easier to add new functions.
- Add a `networkId` prop to the `Widget` component config to allow using a `near` object outside the singleton state to allow testing Mainnet components on a Testnet initialized VM or vice versa. Example usage of `networkId` prop in `Widget` config:
```jsx
// Import widget from testnet initialized VM
<Widget
config={{
networkId: 'mainnet'
}}
src="devgovgigs.near/widget/Ideas" // `src` prop here is a path in mainnet SocialDB
/>
// Also works with the `code` prop where `Social.get` and other [BOS API](https://docs.near.org/bos/api/near#) features and `Widget`s will reference mainnet in this case.
```
- Expose `Ethers.setChain({chainId})` to be able to switch between EVM networks. Note, the gateway should inject it as part of the `EthersProviderContext`.
- Add `config.defaultFinality` to be able to specify `final` instead of `optimistic` (default). It would route the majority of the view calls through the API server.
- Expose `ethers.providers`. You will be able to construct a custom JSON provider for read only data. Example usage:
```jsx
const opGoerliProvider = new ethers.providers.JsonRpcProvider(
"https://optimism-goerli.blockpi.network/v1/rpc/public"
);
console.log(opGoerliProvider);
```
- BREAKING: Update `Ethers.send` to ignore cache and return a promise instead of the cached value.
- Add `loading` prop to a Widget. It would display the passed value instead of the default loading spinner. It can be used to display a custom loading indicator or a placeholder. Example:
```jsx
<Widget
loading={<div style={{width: "100%", height: "200px"}}>Loading...</div>}
src="mob.near/widget/ProfilePage"
/>
```
Add `loading` prop to a Widget. It would display the passed value instead of the default loading spinner. It can be used to display a custom loading indicator or a placeholder. Example:
```jsx
<Widget
loading={<div style={{width: "100%", height: "200px"}}>Loading...</div>}
src="mob.near/widget/ProfilePage"
/>
- Expose `ethers.providers`. You will be able to construct a custom JSON provider for read only data. Example usage:
```jsx
const opGoerliProvider = new ethers.providers.JsonRpcProvider(
"https://optimism-goerli.blockpi.network/v1/rpc/public"
);
console.log(opGoerliProvider);
```
- Add `config.defaultFinality` to be able to specify `final` instead of `optimistic` (default). It would route the majority of the view calls through the API server.
- Expose `Ethers.setChain({chainId})` to be able to switch between EVM networks.
Note:`setChain` callback should be provided by the gateway through `EthersProviderContext`. If it's not provided the call from the VM will fail with an exception. See https://github.com/NearSocial/viewer/pull/174 as an example on how to expose `setChain`